Tearing Hair Out !

M

Mr Newbie

I have a simple datagrid with three columns in it ID, LastName, FirstName.
I have Edit/Update columns enabled and in the update event I have the
following code. The problem is that the LastName and FirstName text boxes
return the unmodified values ( ones before I edit and updated them ). I know
what I am doing wrong must be stupid and simple but I cant see it.

Any ideas where my brain has gone ?

Mr N

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.UpdateCommand

Dim dg As DataGrid = DirectCast(source, DataGrid)

Dim drow As DataRow

Dim myTableCell As TableCell

Dim LastName As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)

Dim FirstName As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)

drow = Me.Ds1.Tables(0).Rows(e.Item.DataSetIndex)

drow("LastName") = LastName.Text

drow("FirstName") = FirstName.Text

Me.SqlDataAdapter1.Update(Ds1)

dg.DataBind()

End Sub
 
N

Norman Yuan

You can very easily debug where thing goes wrong by insert a Break Point at

drow("LastName") = LastName.Text

and step through rest of code.

If "LastName.Text and FirstName.Text do return correct (modified) values,
then you can go to the database to make sure the values being updated to
database correctly (did you checked that?)

If the database gets updated correctly, the the only possible reason,
obviourly, is you did not re-bind data to the DataGrid correctly. from what
I can see, you need:

dg.DataSource=DS1.Tables(0) ''You missed this line of code
dg.DataBind()
 
M

Mr Newbie

Thanks for your reply.

1.) I am well aware of the debugging tools and methods, however the problem
is that the following lines return the values presented in the textboxes
when the UPDATE link is accesed rather than the values which replaced them
when they are edited. For example if the name was Smith, John and I click
the update link and make the name Smith, Jane. The following two lines will
set the names to Smith, John instead of Smith Jane on postback.

2.) I have not forgottent the datasource property as it is set by the wizard
code each time the form is contructed, in fact it if were not set, I would
display nothing.


Any other ideas ?

Mr N
 

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

Top