Datagrid DataGridCommandEventArgs trouble

J

Jim Whipkey

I am using an edit, cancel update button column in a
datagrid. When a user clicks edit all the columns in the
row change to textboxes. So far so good.

The user then changes the contents of one of these boxes
and clicks update.

I use the code below to try and capture the new text into
the tbX.Text property but the OLD text is always
presented. Can anyone tell me what I'm doing wrong? If I
look at the Request.Form information I see the NEW text
but DataGridCommandEventArgs seems to be ignoring the
change and providing the OLD text.

Private Sub DataGrid2_UpdateCommand(ByVal source As
System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles DataGrid2.UpdateCommand
Dim tbX As TextBox = CType(e.Item.Cells(5).Controls
(0), TextBox)
DataSet11.ATEducation(e.Item.ItemIndex)("School")
= tbX.Text
End Sub

This is the first time I've tried this so I'm hoping it's
something simple I've overlooked.

Thanks for any help you can provide.
Jim
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Thanks for posting in this group.
Based on my understanding, when you click update button in the "edit,
cancel update button column", UpdateCommand event fires, but the Dim tbX
As TextBox = CType(e.Item.Cells(5).Controls(0), TextBox) will get the
original Text of that editbox.
I think this is a strange behavior, and I can not reproduce out. In my
project, I can succeed get the new text value.
To use "edit, cancel update button column", you should set
MyDataGrid.EditItemIndex = e.Item.ItemIndex in Edit event.(Also bind the
grid).
In Cancel event, you should set MyDataGrid.EditItemIndex = -1, and bind the
datagrid again.

The link below shows you a little sample about this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwebuiwebcontrolsdatagridclassupdatecommandtopic.asp

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jim Whipkey

Thanks for your replies Jeff and Ken.

I found the problem in my Page_Load subroutine. I had the
following code executing on every load. This re"binded"
the data to the datagrid, populating the textbox with the
old value from the database every time before my update
code had a chance to happen.

Me.SqlSelectCommand1.Parameters("@UserID").Value = Session
("UserID")
SqlDataAdapter1.Fill(DataSet11.ATExperience)
DataGrid2.DataSource = DataSet11.ATEducation
DataGrid2.DataBind()

I fixed it by doing this

Me.SqlSelectCommand1.Parameters("@UserID").Value = Session
("UserID")
SqlDataAdapter1.Fill(DataSet11.ATExperience)
If Not IsPostBack Then
DataGrid2.DataSource = DataSet11.ATEducation
DataGrid2.DataBind()
End If

which bound the data to the grid on the initial load only
and then did the bind after performing the updatecommand.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top