Gridview button field only works on page 1 of grid

Discussion in 'ASP .Net' started by Julia B, Mar 9, 2010.

  1. Julia B

    Julia B Guest

    Hi all

    I've got a gridview in a Visual Studio 2005, .NET version 2.0 web app, which
    displays many records. The grid's AllowPaging and AllowSorting properties are
    set to true with the grid displaying 10 records per page.

    There is a buttonfield column in the gridview which fires the grid
    rowcommand event as follows:

    Dim index As Integer
    Dim selectedRow As GridViewRow
    Dim filePath As String
    'find the serial number of the record and open its change history
    index = Convert.ToInt32(e.CommandArgument)
    selectedRow = Me.SearchGrid.Rows(index)
    Dim serialNumber As String = selectedRow.Cells(3).Text
    Response.Redirect("ChangeHistory.aspx?SN=" & serialNumber)

    This supposedly opens another page in the application based on the record
    selected. If the user does this on the first page of the grid (i.e. the first
    10 records) this works fine. However if the user sorts the records or goes to
    another page, when they click on the button field, the record that opens is
    one from the first page of the grid. The sort and page change don't seem to
    be recognised by the grid even though the user can see the change.

    Any ideas on what I need to do?

    Thanks
    Julia
     
    Julia B, Mar 9, 2010
    #1
    1. Advertising

  2. Julia B

    Julia B Guest

    Hi, problem solved. All I needed to do was rebind the grid during the grids
    PageIndexChanging event and then set the pageindex to the new pageindex as
    follows:

    Me.SearchGrid.DataBind()
    Me.SearchGrid.PageIndex = e.NewPageIndex

    Julia

    "Julia B" wrote:

    > Hi all
    >
    > I've got a gridview in a Visual Studio 2005, .NET version 2.0 web app, which
    > displays many records. The grid's AllowPaging and AllowSorting properties are
    > set to true with the grid displaying 10 records per page.
    >
    > There is a buttonfield column in the gridview which fires the grid
    > rowcommand event as follows:
    >
    > Dim index As Integer
    > Dim selectedRow As GridViewRow
    > Dim filePath As String
    > 'find the serial number of the record and open its change history
    > index = Convert.ToInt32(e.CommandArgument)
    > selectedRow = Me.SearchGrid.Rows(index)
    > Dim serialNumber As String = selectedRow.Cells(3).Text
    > Response.Redirect("ChangeHistory.aspx?SN=" & serialNumber)
    >
    > This supposedly opens another page in the application based on the record
    > selected. If the user does this on the first page of the grid (i.e. the first
    > 10 records) this works fine. However if the user sorts the records or goes to
    > another page, when they click on the button field, the record that opens is
    > one from the first page of the grid. The sort and page change don't seem to
    > be recognised by the grid even though the user can see the change.
    >
    > Any ideas on what I need to do?
    >
    > Thanks
    > Julia
     
    Julia B, Mar 9, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. notTold

    OnTextChanged only works for first textbox in grid?

    notTold, May 20, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    120
    notTold
    May 20, 2004
  2. Steve Mauldin
    Replies:
    3
    Views:
    331
    Steve Mauldin
    Aug 11, 2004
  3. qa4ever
    Replies:
    3
    Views:
    245
  4. Chuck
    Replies:
    0
    Views:
    271
    Chuck
    Nov 10, 2003
  5. Sound
    Replies:
    2
    Views:
    454
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page