Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim fName, lName As String
' Gets the value of the key field of the row being updated
' Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim key As String
Try
key = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Catch
key = DataGrid1.DataKeys(0).ToString()
End Try
' 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(1).Controls(0), TextBox)
fName = tb.Text
' Gets the value the TextBox control in the fourth column
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
lName = 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 dsCategories1.employeeRow