日期:2014-05-19  浏览次数:20500 次

关于GRIDVIEW删除操作的问题!高手进!
前几天看到有大侠的贴子!
1.GridView1.DataKeyNames   =   new   string[]   {   "id "   };  
2.string   id=GridViews1.DataKeys[i][ "id "].ToString();

用2在删除时取关键字的值为什么总提示超出索引范围?




------解决方案--------------------
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex][ "id "].ToString();
......
}
------解决方案--------------------
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (e.Row.RowIndex == -1)
return;
string id = GridView1.DataKeys[e.RowIndex][ "id "].ToString();
......
}