I'm trying to set the GridView1_RowEditing to the ID of the gridview but not the index because it causes problems when the end user searches the value and edits a row. I've changed my code from this:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindGridView();
}
to this:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Label ID = (Label)GridView1.Rows[e.NewEditIndex].FindControl("ID");
BindGridView();
}
The ID is the name of column in the Database.
but I'm getting this error when I click the edit button the second time:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.