The exception that is thrown when an attempt is made to access an element of an array with an index that is outside the bounds of the array.[
^]
It seems your grid has no
DataKeys[
^]. Are you sure your
GridView[
^] is filled with records? Because that doesn't seem to be the case.
Anyway, simply debugging and stepping through the code should reveal if
GridView.DataKeys[0]
does actually exist.
Edit:
You should always use the Count or Length (extension) method or Property of collections to make sure there are enough objects in the collections before trying to access one.
Consider the following:
if (GridView.DataKeys.Count > 0)
{
GridView.DataKeys[0].Value.ToString()
GridView.DataKeys[1].Value.ToString()
}
Hope that helps :)