Click here to Skip to main content
15,388,796 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
int ID = Convert.ToInt32(GVDetails.DataKeys[e.RowIndex].Values["ID"]);

TextBox txtName = GVDetails.Rows[e.RowIndex].FindControl("txtName") as TextBox;
TextBox txtAddress = GVDetails.Rows[e.RowIndex].FindControl("tctAddress") as TextBox;
SqlCommand cmd = new SqlCommand("update MyGrid set Name='" + txtName + "',Address='" + txtAddress + "' where ID=" + ID, con);
GVDetails.EditIndex = -1;
when i click on delete button it gvs error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Sergey Alexandrovich Kryukov 11-Jun-13 22:50pm
In what line?
mohdniyaz169 11-Jun-13 23:01pm
in first line
int ID = Convert.ToInt32(GVDetails.DataKeys[e.RowIndex].Values["ID"]);

1 solution

It's either GVDetails.DataKeys or GVDetails.Rows, or both, have number of element less then e.RowIndex − 1, maybe even 0. You can check it all if you execute your code under debugger. Find out the reason and check the size of a collection/array before accessing an element by index.


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