Index was out of range. Must be non-negative....
Hi,
I get this error :
Code:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Error is on this line:
Code:
string rowID;
rowID = DataGridSpirits.DataKeys[e.Item.ItemIndex].ToString();
I have a datagrid, i have a delete and update buttons. This error occurs on both of these events. SOmething to do with returning the row number. It worked earlier, i didn't change anything???
Any help greatly appreciated.
Re: Index was out of range. Must be non-negative....
Sounds silly but have you set a DataKeyField for the DataGrid?
If you have could you post the full method that handles the update and also the DataGrid declaration.
DJ
Re: Index was out of range. Must be non-negative....
Additionally, make sure your code is only executing on a Row or AlternatingRow and not on the headers or footers.
Test the value of e.Item.ItemIndex before you attempt to use it
Re: Index was out of range. Must be non-negative....
Thanks to both of you!
For some bizarre reason the DataKeyField was deleted from my webForm, probably due to my clumsyness. Anyway all working now! :)
Thanks