In the VB behind a GridView I've got the DataBound method below.
The .aspx page loads as long as a row happens to already be in Edit mode, but if I click Cancel or Save, I get:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
on row 2 below.
It seems that the "EditIndex" is Nothing when it's not in Edit mode and throwing the out of range error. How can I avoid the error when the GridView is not in Edit mode?
Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
Dim iReqID As Integer = CType(GridView1.DataKeys(GridView1.EditIndex).Value, Integer) 'CInt(GridView1.DataKeys(GridView1.EditIndex).Value)
Dim iModifiedBy As String = iUserName
Call SendModifiedByToRequisition(iModifiedBy, iReqID)