Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 549
  • Last Modified:

How to Update datagrid row when paging

Using a datagrid with a web form.  Its bound to a dataset.  I have enabled paging, and I have a edit command button.  when I edit then, update it updates the correct row, but if I go to page 2 and select row 6 it updates for 6 on page 1.  So not sure what has to change on row_updating or row_editing.  Here is my code.

thanks

Private Sub gvItems_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvItems.RowUpdating
        Dim myrow As GridViewRow = gvItems.Rows(e.RowIndex)
        Dim tbHrs As New TextBox
        
        ' Dim tbUpPrice As New CheckBox
        ' Dim myItem As Integer = CInt(myrow.Cells(1).Text)

        tbHrs = CType(myrow.Cells(6).Controls(0), TextBox)
        
        ds.Tables(0).Rows(e.RowIndex).Item(8) = tbHrs.Text
        ds.Tables(0).AcceptChanges()

        gvItems.EditIndex = -1
        gvItems.DataSource = ds.Tables(0)
        gvItems.DataMember = "ID"
        gvItems.DataBind()
    End Sub

 Private Sub gvItems_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvItems.RowEditing
        gvItems.EditIndex = e.NewEditIndex
        gvItems.DataSource = ds.Tables(0)
        '  gvItems.DataMember = "ID"
        gvItems.DataBind()
    End Sub

Open in new window

0
mgmhicks
Asked:
mgmhicks
1 Solution
 
CodeCruiserCommented:
Try changing

ds.Tables(0).Rows(e.RowIndex).Item(8) = tbHrs.Text

to

ds.Tables(0).Rows(myrow.DataItemIndex).Item(8) = tbHrs.Text

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now