Solved

GridView DataBound - values not set when EdiIndex <> -1

Posted on 2010-11-09
6
288 Views
Last Modified: 2012-05-10
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 SendModifiedByToRequisition 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)
    End If
End Sub

Open in new window

0
Comment
Question by:megnin
  • 3
  • 3
6 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34093550
I think you're probably using the wrong events for whatever it is you are trying to achieve. You should probably be looking at the RowEditing and RowUpdating/RowUpdated events instead.
0
 
LVL 1

Author Comment

by:megnin
ID: 34093587
Hi again, Carl.  Yes, I was thinking the same thing.  My experience level is not very high so I'm not sure what event to use when.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34093605
Basically it's like this:

     Editing - Fired when the gird enters edit mode
     Updating - Fires when switching back to Read mode, but before data is committed
     Updated - Fires when switching back to Read mode and after data is committed

Updating fires prior to Updated.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:megnin
ID: 34094078
It looks like RowUpdated is where I want to put it.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34094157
Sounds like it to me too :)
0
 
LVL 1

Author Closing Comment

by:megnin
ID: 34094161
Yep.  RowUpdated seems to be working fine.  Thank you again, Carl.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question