如何取得Gridview內自訂按鍵所屬的RowIndex

 protected void Button1_Click(object sender, EventArgs e)
 {
 int rowIndex = ((GridViewRow)((Control)sender).NamingContainer).RowIndex;
 }
 
   protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {

         //設定按鍵的RowCommandName 是GridInsert,判斷是Button傳來的RowCommand
         if (e.CommandName == "GridInsert")          {
            GridViewRow rowSelect = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
            int rowindex = rowSelect.RowIndex;
        }
 

https://dotblogs.com.tw/wookpecker/2016/04/08/111349

 

跳至工具列