How to Update datagrid row when paging

Posted on 2011-10-21
Last Modified: 2012-05-12
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.


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

        gvItems.EditIndex = -1
        gvItems.DataSource = ds.Tables(0)
        gvItems.DataMember = "ID"
    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"
    End Sub

Open in new window

Question by:mgmhicks
    1 Comment
    LVL 83

    Accepted Solution

    Try changing

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


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


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now