这里面的RowIndex 怎么也不能引用
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
string tea = this.GridView1.DataKeys[e.RowIndex].ToString();
}
是怎么回事,是不是还哪里需要设置
------解决方案-------------------- protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
gv.EditIndex = e.RowIndex;
int id = int.Parse(gv.DataKeys[e.RowIndex].Value.ToString());
gv.EditIndex = -1;
BindData();
}
protected void gv_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
//没有e.RowIndex
}
------解决方案--------------------楼主事件用的不对吧
------解决方案--------------------protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
string tea = this.GridView1.DataKeys[e.Row.RowIndex].ToString();
}
------解决方案--------------------在给GridView绑定数据时,你给GridView设置主键了吗?
GridView1.DataSource="";
GridView1.DataKeyNames=new string[]{"id"};(这里必须和数据库中的字段保持一致)
GridView1.DataBind();
------解决方案--------------------这个e.RowIndex 在每个事件里面都有不同的,C/S和B/S又有不同。先弄清楚你触发的事件
------解决方案--------------------protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
string tea = new DataKey(e.Keys).Value.ToString();
}