LinkButton,設定 CommandName(如 "lbtn")。RowCommand 事件中:protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "lbtn")
{
GridViewRow gvrow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int index = gvrow.RowIndex;
string userid = GridView1.Rows[index].Cells[欄位索引].Text.Trim();
// 後續邏輯...
}
}
關鍵點:NamingContainer 取得包含該按鈕的 GridViewRow,再以 RowIndex 存取 Rows 集合。