Gridview button field only works on page 1 of grid

J

Julia B

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
 
J

Julia B

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top