Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-11-09
6
Medium Priority
?
321 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

916 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