http://www.cnblogs.com/Jinglecat/archive/2007/07/05/806460.html
方法一:
step1: 设置你的GridView的DataKeyNames为re_id
<asp:GridView ID= "GridView1 " runat= "server " DataKeyNames= "re_id " ...
step2: 在RowCreated事件中给按钮的CommandArgument属性赋值为当前行索引
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton addButton ;
if (e.Row.RowType == DataControlRowType.DataRow)
{
addButton = (LinkButton)e.Row.Cells[0].Controls[0];//请确认你的按钮的位置
if (addButton != null)
{
if (addButton.CommandName== "add ")
addButton.CommandArgument = e.Row.RowIndex.ToString();
}
}
}
step3: 在RowCommand中得到此行主键列
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "add ")
{
Response.Write(GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString());
}
}
**** 还没来得及验证对否,但是无意中发现的,觉得不知道什么时候会用到,所以先留起来,^0^ ****