this.GridView1.DataKeyNames = new string[] { "Id" }//在进行数据绑定是记得写上 id是你的主键字段名字
用string id=this.GridView1.DataKeys[e.rowIndex].value.toString();使用。一般在删除和更新时使用。
我的也是在后台绑定的呀,不显示主键列也行啊
this.GridView1.DataSource = bll.DepInfo();//指定数据源
this.GridView1.DataKeyNames = new string[] { "Id" };//设定主键 默认不显示该列的
this.GridView1.DataBind();//绑定数据
protected void GridView1_RowCreated1(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
}
既隐藏有可以得到他的值
给DataKeyFiled属性赋值。就是主键字段名。