首先要绑定GridView的主键
this.GridView1.DataKeyNames = new string[] { "ID" };
第一种方法
protected void btnEnd_Click(object sender, EventArgs e)
{
int rowIndex = ((GridViewRow)(((Button)sender).NamingContainer)).RowIndex;
string id = GridView1.DataKeys[rowIndex].Value.ToString();
}
第二种方法
<asp:Button ID="btnDelete" runat="server" UseSubmitBehavior="false" OnClick="btnDelete_Click" CommandArgument='<%#Eval("ID")%>' />
protected void btnDelete_Click(object sender, EventArgs e)
{
string id = ((Button)sender).CommandArgument.ToString();
ifusion.BLL.WT bll = new ifusion.BLL.WT();
bll.Delete(id);
bind();
}