Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid OnUpdateCommand - cannot retrieve value from editable field

Status
Not open for further replies.

Gert74

Technical User
Jan 26, 2001
48
NL
Hello,

I'm new to ASP.NET and ran into this problem which is driving me nuts. I have a datagrid which is bound with a dataset. I wan't the user to be able to change the column Aantal.

When the OnUpdateCommand is fired I really have trouble to retrieve the new filled in value. Everytime it's returning the old value. This is my code:


**********
Public Sub Grid_Update(Sender as Object, e As DatagridCommandEventArgs)
Trace.Write("Event Notification", "Grid_Update Fired")
Dim MyDS as Dataset = LoadMyDS
Dim newAantal As String
Dim row As Integer = CInt(e.Item.ItemIndex)
Trace.Write("Status Notification", "Row = " & row)
newAantal = CType(e.Item.FindControl("Hoeveelheid"), TextBox).Text
Trace.write("Status Notification", "newAantal = " & newAantal)
dgBestellijst.EditItemIndex = -1
MyDS.Tables(0).Rows(row).Item("Aantal") = newAantal

dgBestellijst.DataSource = MyDS
dgBestellijst.EditItemIndex = -1
dgBestellijst.DataBind()
session("MyDS") = MyDS
Trace.Write("Status Notification", "session(MyDS) = MyDS")
End Sub
************

The problem is not a cached version or something with Postback, because when I change the line:
MyDS.Tables(0).Rows(row).Item("Aantal") = newAantal
with
MyDS.Tables(0).Rows(row).Item("Aantal") = 3
everything is updated as expected.

The problem is that
newAantal = CType(e.Item.FindControl("Hoeveelheid"), TextBox).Text
doesn't give the new edited value, but the old one.

My HTML lines for this piece are:
**********
<asp:TemplateColumn HeaderText=&quot;Aantal&quot;>
<ItemTemplate>
<asp:Label runat=&quot;server&quot; text='<%# DataBinder.Eval(Container, &quot;DataItem.Aantal&quot;) %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=&quot;Hoeveelheid&quot; runat=&quot;server&quot; Width=&quot;20&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.Aantal&quot;) %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
************

Someone please help me, I'm desperate!!!

Thanks in advance,
Gert

Gert
 
Found the solution:

It's written in this article:

I had this in my Page_Load:
If page.ispostback() Then
dgBestellijst.DataSource = MyDS
dgBestellijst.Databind()
......... etc.

The databind() is the problem. It should not be done on a postback:
If page.ispostback() Then
dgBestellijst.DataSource = MyDS
'dgBestellijst.Databind()




Gert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top