Results 1 to 2 of 2

Thread: UpdateCommand not update

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Angry 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

  2. #2
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    I found a great tutorial that helped me a lot with editing data grids.
    http://www.dotnetjunkies.com/tutoria...tutorialid=421
    Hopefully helps
    Cheers
    Soylent Green tastes like chicken

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width