Solved

can't fetch updated value in edit mode

Posted on 2009-04-06
6
328 Views
Last Modified: 2013-11-07
i have a datagrid on a web page which is bound to an OLEDB datasource.  It queries data fine but when i try to retrive the value of a cell when Edit mode, it simply returns the previous data.  I have tried to fetch the data in the RowUpdating event, but it is the old data.  The RowUpdated event doesn't even fire.  How do i retrieve the updated values?  I'm trying to "intercept" the update and apply an update statement of my own.
Protected Sub GV1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GV1.RowUpdating
        Dim txtActive As TextBox = DirectCast(GV1.Rows(e.RowIndex).Cells(2).Controls(0), TextBox)
        Dim strActive As String = txtActive.Text  'This always returns the old value
 
        Dim txtID As TextBox = DirectCast(GV1.Rows(e.RowIndex).Cells(1).Controls(0), TextBox)
        Dim strID As String = txtID.Text   'This always returns the old value
 
        Dim txtPerson As TextBox = DirectCast(GV1.Rows(e.RowIndex).Cells(3).Controls(0), TextBox)
        Dim strPerson As String = txtPerson.Text    'This always returns the old value
 
        Dim txtZip As TextBox = DirectCast(GV1.Rows(e.RowIndex).Cells(4).Controls(0), TextBox)
        Dim strZip As String = txtZip.Text
        Dim strCmd As String
 
        strCmd = "Update PurchaseList SET Available = " & strActive & ",  UserName =  '" & strPerson & "', PurchaseZip = " & strZip & " WHERE ID = " & strID
 
        Dim strConnection As String = System.Configuration.ConfigurationManager.AppSettings("ConnectionStr")  'Get Connection string from Web.Config file
        Dim myCon As New OleDbConnection(strConnection)
        myCon.Open()
 
        Dim myCmd As New OleDbCommand(strCmd, myCon)
        myCmd.ExecuteNonQuery()
        Me.GV1.EditIndex = -1
        myCon.Close()
        Me.ProcessGridView()
 
    End Sub

Open in new window

0
Comment
Question by:lanier3532
[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
  • 2
6 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 24077247
Try the rowCommand event, any event of grid will first fire the rowcommand event
0
 

Author Comment

by:lanier3532
ID: 24080008
That doesn't seem to give me access to the new grid values entered during edit mode, only the command arguments.  I must be missing something.  I've attached a screen shot of the edit session.

As you can see from the screen shot, i've changed the value of Active from 1 to a 0.  After pressing the Update link, when i try to access the cell data using the code previously in this thread, it returns a value of 1 instead of 0.

Grid-Pic.gif
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 24125753
How do you bind the grid? Are you sure you do not rebind it on postback? I mean are you using the
If Not page.IsPostBack Then
   Grid.datasource = ..
   Grid.DataBind()
End If
0
 

Author Closing Comment

by:lanier3532
ID: 31567017
that was it!  Sometimes its the obvious that we don't see.
Thanks again!
0

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

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…
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 …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

691 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