ASP.NET GridView RowIndex As CommandArgument

前端 未结 9 1612
天涯浪人
天涯浪人 2020-11-30 23:40

How can you access and display the row index of a gridview item as the command argument in a buttonfield column button?



            


        
9条回答
  •  [愿得一人]
    2020-12-01 00:42

    I typically bind this data using the RowDatabound event with the GridView:

    protected void FormatGridView(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
       if (e.Row.RowType == DataControlRowType.DataRow) 
       {
          ((Button)e.Row.Cells(0).FindControl("btnSpecial")).CommandArgument = e.Row.RowIndex.ToString();
       }
    }
    

提交回复
热议问题