中国名模排名:ADO.NET中的datagrid更新出错

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/05 07:06:24
报的是这个错
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

错误的语句是
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();

页面的datagrid有四列,前三列是可修改的,最后一列是更新按钮列

在先前一个更新中没有出错,只是先前的那个datagrid只有两列,要更新的是第一列
更新是在按了编辑这样一个linkButton后出现的,和取消一起

已经解决了,是要在datagrid的DataKeyField中设置主键,谢谢回答的人

string key = DataGrid1.DataKeys[e.Item.ItemIndex-1].ToString();