Index was out of range. Must be non-negative and less than the size of the collection.
{ GridViewRow row = GridView1.Rows[e.RowIndex]; int customerId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[1]); string name = (row.FindControl("txtName") as TextBox).Text; string country = (row.FindControl("txtCountry") as TextBox).Text; string query = "UPDATE Customers SET Name=@Name, Country=@Country WHERE CustomerId=@CustomerId"; string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query)) { cmd.Parameters.AddWithValue("@CustomerId", customerId); cmd.Parameters.AddWithValue("@Name", name); cmd.Parameters.AddWithValue("@Country", country); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } GridView1.EditIndex = -1; this.BindGrid(); }
e.RowIndex
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)