With the VB below behind a GridView when I step through the code in debug, as I select Edit mode, DataBound fires and iReqID becomes the correct value of the DataKey and iModifiedBy becomes the correct value of iUserName.
When I click "Save", the DataBound fires again and iReqID is 0 and iModifiedBy is "" because it's no longer in Edit mode and the values are not set and SendModifiedByToRequisitio
n doesn't get called. Crap, this is like a catch 22.
Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
If GridView1.EditIndex <> -1 Then
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)