<asp:GridView ID="gvDuty" DataKeyNames="SetNo" runat="server" AutoGenerateColumns="False" OnRowCommand="gvDuty_RowCommand">
....
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnEnd" CommandName="CheckOut" Enabled="false" runat="server">CheckOut</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
后台:
protected void gvDuty_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument); //获取当前行
....
}
为么e.CommandArgument显示为""呢??请知道的大哥不吝赐教,谢谢啊~~~
....
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnEnd" CommandName="CheckOut" Enabled="false" runat="server">CheckOut</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
后台:
protected void gvDuty_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument); //获取当前行
....
}
为么e.CommandArgument显示为""呢??请知道的大哥不吝赐教,谢谢啊~~~
VS2005我不懂,猜的。^_^
我们可以把CommandName设为Select,Delete,或是Edit等,然后我们就可以获取到命令行了,如下:
protected void gvUserList_RowCommand(object sender, GridViewCommandEventArgs e)
{
CommandSourceID = ((Control)e.CommandSource).ID;
}
protected void gvUserList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (CommandSourceID == "btnRemoveUserFromRole")
{
e.Cancel = true;
GridViewRow row = gvUserList.Rows[e.RowIndex];
int userId = int.Parse(row.Cells[0].Text.Trim());
...... }
}
private string CommandSourceID = "";
protected void gvUserList_RowCommand(object sender, GridViewCommandEventArgs e)
{
CommandSourceID = ((Control)e.CommandSource).ID;
}
protected void gvUserList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (CommandSourceID == "btnRemoveUserFromRole")
{
e.Cancel = true;
GridViewRow row = gvUserList.Rows[e.RowIndex];
int userId = int.Parse(row.Cells[0].Text.Trim()); }
}
感觉Gridview不爽!
哪里/谁说 Convert.ToInt32(e.CommandArgument); 就是index了?