Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In RowUpdating Event,

RowIndex is coming Null,

and the error is...

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

GV.DataKeys[e.RowIndex].Value;

But Gridview loaded with data, with datakeys too.

What I have tried:

I have tried with Gridview data, Datakeys are there but i could n't find where the bug is...

I have tried the following links too...

http://www.codeproject.com/Questions/1105358/Html-drop-down-list-shows-past-dates-value
http://www.codeproject.com/Questions/414868/Index-was-out-of-range?tab=mostrecenthttp://www.codeproject.com/Questions/414868/Index-was-out-of-range?tab=mostrecent
http://stackoverflow.com/questions/5381670/index-was-out-of-range-error-in-gridview
http://forums.asp.net/t/1634281.aspx

But I cant find the solution.

Thanks in Advance.
Posted
Updated 8-Jun-16 2:48am
Comments
VR Karthikeyan 8-Jun-16 5:28am    
As per the error, it says the RowIndex value must be non negative integer value that is less than the size of the array. you said RowIndex is become null when you run the code. Just put a breakpoint in your code and debug it, you will find it.

1 solution

Hi, can you please post your code here for binding your GridView and for your RowUpdating event?
 
Share this answer
 
Comments
sankarmca86 8-Jun-16 9:00am    
Thanks for your reply, i already posted that...

Label Lbl1 = (Label)GV.Rows[e.RowIndex].FindControl("lblex");

In Gridview GV, i gave a label named as "lblex"; but i got error in RowIndex.

which means, i cannot get that row.
Vincent Maverick Durano 8-Jun-16 9:47am    
I want to see your GridView markup and how you are binding it. It's hard to troubleshoot an issue if you are just showing a line of code.

By the way did you set the DataKeyNames in your GridView?

If you want to implement CRUD operations in gridview, Here are some step by step examples that you can refer:

If using BoundField Columns: http://geekswithblogs.net/dotNETvinz/archive/2009/02/22/gridview-insert-edit-update-and-delete--the-ado.net-way.aspx
If using TemplateField Columns: http://geekswithblogs.net/dotNETvinz/archive/2009/06/10/adding-rows-in-gridview-with-edit-update-and-delete-functionality.aspx
Kats2512 8-Jun-16 10:16am    
what you have provided is of no use, even though this line of code is correct to find your label we would need to see what happens before and after it gets to this line of code.

Please use the improve question to post up the code snipped for your gridview.
Richard Deeming 8-Jun-16 10:16am    
Do not post comments as solutions. Use the "Have a Question or Comment?" button under the question to post a comment.
Vincent Maverick Durano 8-Jun-16 10:22am    
Thanks Richard. Noted. I'm pretty new to this forum community and I'm trying to familiarize myself with it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900