Problem with datagrid when i hit the update button (sql)

plugged

Member
Joined
Sep 13, 2005
Messages
11
Programming Experience
3-5
basically i have a datagrid with an edit, cancel and update colunm on it, now everything works fine until i get to the edit mode and enter in new values. Then when the code tries to read the new value i have entered it always only gets the old ones.

This is a copy of my code

Private Sub DataGrid1_CancelCommand1(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_EditCommand1(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_UpdateCommand1(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim Name, Department As String
Dim primary(0) As System.Data.DataColumn
primary(0) = DSemp1.TblEmployees.EmpIDColumn
DSemp1.TblEmployees.PrimaryKey = primary
' Gets the value of the key field of the row being updated
Dim key As Integer = DataGrid1.DataKeys(e.Item.ItemIndex)
' Gets get the value of the controls (textboxes) that the user
' updated. The DataGrid columns are exposed as the Cells collection.
' Each cell has a collection of controls. In this case, there is only one
' control in each cell -- a TextBox control. To get its value,
' you copy the TextBox to a local instance (which requires casting)
' and extract its Text property.
'
' The first column -- Cells(0) -- contains the Update and Cancel buttons.
Dim tb As TextBox
' Gets the value the TextBox control in the third column
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
Name = tb.Text
' Gets the value the TextBox control in the fourth column
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
Department = tb.Text
' Finds the row in the dataset table that matches the
' one the user updated in the grid. This example uses a
' special Find method defined for the typed dataset, which
' returns a reference to the row.
Dim r As DSemp.TblEmployeesRow
r = DSemp1.TblEmployees.Rows.Find(key)
' Updates the dataset table.
r.Name = Name
r.Department = Department
' Calls a SQL statement to update the database from the dataset
SqlDataAdapter1.Update(DSemp1)
' Takes the DataGrid row out of editing mode
DataGrid1.EditItemIndex = -1
' Refreshes the grid
DataGrid1.DataBind()
End Sub

can any one tell me what the problem is?

Cheers
Plugged
 
Back
Top