I have a GridView on my page and I click on Edit
, it displays my editable text box but when I edit the value and press Update
it errors:
The error suggests that GridView2.DataKeys
is null
.
I adding some extra debugging by:
int test = e.RowIndex
and this gives me a value of 0
My code is below:
Can you suggest why im getting:
An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int DataKeyValue = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)GridView2.Rows[e.RowIndex];
Label lblID = (Label)row.FindControl("lblID");
TextBox GVtxtNextStep = (TextBox)row.Cells[0].Controls[0];
GridView2.EditIndex = -1;
cobj.SupportRef1 = txtSupportRef.Text;
cobj.NextStep1 = txtNextStep.Text;
bobj.MicroTicketUpdate(cobj);
GridView2.DataBind();
}