Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial