lanier3532
asked on
can't fetch updated value in edit mode
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
Try the rowCommand event, any event of grid will first fire the rowcommand event
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that was it! Sometimes its the obvious that we don't see.
Thanks again!
Thanks again!