<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显示为""呢??请知道的大哥不吝赐教,谢谢啊~~~

解决方案 »

  1.   

    你没有给CommandArgument设值吧?
    VS2005我不懂,猜的。^_^
      

  2.   

    CommandArgument的值是动态的,无法确定呀...
      

  3.   

    假如把该行换成GridView自带的BoundButton列的话,就可以取到CommandArgument的值了,但是我想用模板列进行一些判断操作,知道的高手看看怎么弄呢要?
      

  4.   

    模板列的button中没有CommandArgument这个属性吗?
      

  5.   

    解决方法参考:
    我们可以把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());
                ......        }
        }
      

  6.   


    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());        }
        }
      

  7.   

    我也遇到这样的问题,int index = Convert.ToInt32(e.CommandArgument);     //获取当前行总是抱错,用string类型输出为空,但如果你把命令按钮不设成templatefield就是可以的,但那样就不能弹出客户端窗口了。
    感觉Gridview不爽!
      

  8.   

    <asp:LinkButton ID="btnEnd" CommandName="CheckOut" Enabled="false" runat="server" CommandArgument='<% #Eval("gvDuty") %>'>CheckOut</asp:LinkButton>
      

  9.   

    没用过gridview 不过问一下
    哪里/谁说 Convert.ToInt32(e.CommandArgument);     就是index了?