Solved

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

Posted on 2010-11-09
6
269 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now