DataGrid保存数据时出现错误解决办法.

来源:互联网 发布:c语言打开文件源代码 编辑:程序博客网 时间:2024/05/10 14:25
解决办法:
前台设定DataGrid
DataKeyField="ID"

错误提示:


Server Error in '/News' Application.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Description: Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

Line 93: {
Line 94: //取得编辑行的关键字段的值
Line 95: int empID=(int)DataGrid1.DataKeys[e.Item.ItemIndex];
Line 96:
Line 97: //取得文本框中输入的内容

Source File: e:/aspxproject/news/datagridedit.aspx.cs    Line: 95