row index in gridview rowCommand

前端 未结 1 1172
眼角桃花
眼角桃花 2021-01-02 06:41

Just want to transfer value from variable to nother variable :

 protected void gvVariableDetail_RowCommand(object sender, GridViewCommandEventArgs e)
                


        
相关标签:
1条回答
  • 2021-01-02 06:48

    You could use the CommandSource property and cast it's NamingContainer to the GridViewRow. Then you can use it's RowIndex property:

    GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer; 
    int rowIndex    = gvr.RowIndex;
    

    If you want to use the CommandArgument you have to set it from aspx:

    CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' 
    

    then this also works:

    int RowIndex = int.Parse(e.CommandArgument.ToString()); 
    
    0 讨论(0)
提交回复
热议问题