Solved

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

Posted on 2010-11-09
6
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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