Solved

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

Posted on 2010-11-09
6
283 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

23 Experts available now in Live!

Get 1:1 Help Now