W
Wayne Wengert
I am working on a walkthrough that allows editing contents of a datagrid
that is displaying some fields from a table in the Northwind DB. The update
code thay have you enter is shown below. As noted in the code, I am confused
by the statement that DIM's the "r" variable using "dsCategories", not
"dsCategories1". The code works fine but I am trying to understand what is
going on here.
TIA
Wayne
=================== code ======================
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.UpdateCommand
Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim categoryName, categoryDescription As String
Dim tb As TextBox
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
categoryName = tb.Text
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
categoryDescription = tb.Text
Dim r As dsCategories.CategoriesRow <= What is
"dsCategories"? My solution shows "dsCategories1"?
r = DsCategories1.Categories.FindByCategoryID(key)
r.CategoryName = categoryName
r.Description = categoryDescription
SqlDataAdapter1.Update(DsCategories1)
DataGrid1.DataBind()
'Switch current row out of edit mode
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
=====================================================================
that is displaying some fields from a table in the Northwind DB. The update
code thay have you enter is shown below. As noted in the code, I am confused
by the statement that DIM's the "r" variable using "dsCategories", not
"dsCategories1". The code works fine but I am trying to understand what is
going on here.
TIA
Wayne
=================== code ======================
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.UpdateCommand
Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim categoryName, categoryDescription As String
Dim tb As TextBox
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
categoryName = tb.Text
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
categoryDescription = tb.Text
Dim r As dsCategories.CategoriesRow <= What is
"dsCategories"? My solution shows "dsCategories1"?
r = DsCategories1.Categories.FindByCategoryID(key)
r.CategoryName = categoryName
r.Description = categoryDescription
SqlDataAdapter1.Update(DsCategories1)
DataGrid1.DataBind()
'Switch current row out of edit mode
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
=====================================================================