|
-
Oct 20th, 2005, 08:24 PM
#1
Thread Starter
Hyperactive Member
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.
-
Oct 21st, 2005, 09:45 AM
#2
Frenzied Member
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
If I have been helpful please rate my post. If I haven't tell me!
-
Oct 21st, 2005, 11:48 AM
#3
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
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Oct 21st, 2005, 02:04 PM
#4
Thread Starter
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|