
index was out of range, must be non-negative and less than..
while changing page no 2 to 1 giving error "Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index"


Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jitendra KumarPosted Dec 31, 2014, 7:35 AM
The error says "The index is out of range".
That means you were trying to index an object with a value that was not valid.
If you have two books, and I ask you to give me your third book,
you will look at me funny. This is the computer looking at you funny.
You said - "create a collection". So it did.
But initially the collection is empty: not only is there nothing in it - it has no space to hold anything.
"It has no hands".
It means that you are accessing a location or index which is not present in collection.
To find this, Make sure your Gridview has 5 columns as you are using it's 5th column by this line
dataGridView1.Columns[4].Name = "Amount";
Here is the image which shows the elements of an array. So if your gridview has less column then the (index + 1) by which you are accessing it, then this exception arises.
See Link Below :-
http://stackoverflow.com/questions/19162248/index-was-out-of-range-must-be-non-negative-and-less-than-the-size-of-the-colle