-
UpdateCommand not update
Hi,
I have a datagrid on my web form, i want update some of the grid cell, but can not get it work. Can you help?
The following is my code:
Private Sub grdProduct_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdProduct.UpdateCommand
'1.get the key for the grdProduct row
Dim pid
pid = grdProduct.DataKeys(e.Item.ItemIndex).ToString
Me.Response.Write(pid)
'2.get the changed value out of the grdProduct
Dim namebox As TextBox
namebox = CType(e.Item.Cells(1).Controls(0), TextBox)
Dim name As String = namebox.Text
'3.find the corresponding row int the data table
Dim r As DSAllProduct.tblProductsRow
r = Me.DsAllProduct1.tblProducts.FindByProductIndex(pid)
'4.update the row by changing values in the row that was located in step 3
r.Name = name
Me.Response.Write(name)
'5.send change from the dataset to the database by calling the data adapter's Update method
Me.DAProduct.Update(Me.DsAllProduct1)
Me.grdProduct.DataBind()
'6.switch the current row in the grid out of editing mode
Me.grdProduct.EditItemIndex = -1
'7.refresh the grdProduct control
Me.grdProduct.DataBind()
End Sub
-
I found a great tutorial that helped me a lot with editing data grids.
http://www.dotnetjunkies.com/tutoria...tutorialid=421
Hopefully helps
Cheers