all groups > asp.net webcontrols > march 2007 >
You're in the

asp.net webcontrols

group:

GridView - Can't get textbox value in RowUpdating


GridView - Can't get textbox value in RowUpdating Josh Schmidt
3/27/2007 3:45:27 PM
asp.net webcontrols:
Hey All,

I'm building shopping cart that stores selected items in a cookie. I have a
class that handles converting the cookie to a datatable and binding it to a
GridView. I've added a CommandField to handle removing items, and that all
works great. Now I want to add an EditTemplate to edit the quantity of
items. I added a textbox to the EditTemplate for the Qty column and bind it
to the Qty value from the datatable. I've handled the RowEditing and
RowCanceling Events, and I can successfully switch to edit mode and change
the value there.

Here is where the problem starts. When I hit update on the editing row, the
RowUpdating event fires. I go to get the new value entered in the Qty box,
and all I get is the old value.

Here is the code I'm using:

Protected Sub gvCart_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvCart.RowUpdating

Dim ctQty As TextBox = gvCart.Rows.Item(e.RowIndex).FindControl("txtQty")

lblMsg.Text = ctQty.Text

BindCart()

End Sub

----------------------------------------

Bind Cart receives the datatable from another class, sets the datasource on
the gridview and calls databind.

I've tried going into the Cells with DataControlFieldCell, but I still just
get the old value.

Any help would be greatly appreciated!



RE: GridView - Can't get textbox value in RowUpdating Josh Schmidt
3/27/2007 6:03:37 PM
I spent a couple of hours working on this problem. Literally two minutes
after posting this I found the solution. After banging my head on my desk
for a little while I thought I would post the answer:

Don't rebind the GridView on PostBack!

Yes, I really am that brilliant. After only binding when Not IsPostBack in
my Page_Load event everything works wonderfully.

Thanks anyway!

Josh

[quoted text, click to view]
AddThis Social Bookmark Button