You don't have to use JavaScript....
It's actually pretty easy to do.
Add some controls to the page that will preform your custom paging. The controls I typically use are 2 LinkButtons (one for moving one page forward and one for moving one page back) and a DropDownList in between them which lists all of the possible pages and allows the user to automatically jump to the page that they want to.
Whenever the GridView's DataSource is changed I make sure to update the DropDownList so that it contains the number of pages that the GridView displays.
Implementing "custom paging" is really extremely simple.
In the event handler for the LinkButtons I increment or decrement the Grid's PageIndex by 1... unless the control is at the first page or the last page of course.
If the user selects a value from the DropDownList I change the PageIndex to the value that they selected.
After I change the PageIndex I check to see if the user is at the first or last page...if so I disable the paging controls that allow the user to move forward or back.
Like I said it's really really simple.
Here's an example of a method that handles the "PreviousPage" link button click event:
-
Private Sub PreviousPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PreviousPage.Click
-
If MyGridView.PageIndex > 0 Then
-
MyGridView.PageIndex = MyGridView.PageIndex - 1
-
'QuickSelectPageList is the DropDownList that lets the user jump between pages
-
QuickSelectPageList.ClearSelection()
-
QuickSelectPageList.Items(MyGridView.PageIndex).Selected = True
-
End If
-
End Sub
Here is an example of code that I use to populate the DropDownList that lets the user jump between pages:
-
Private Sub InitializeGridViewQuickSelectDropDownList()
-
Dim numpages = MyGridView.PageCount
-
QuickSelectPageList.Items.Clear()
-
'Populating the Quick Page Select drop down list
-
For i As Integer = 0 To numpages - 1
-
QuickSelectPageList.Items.Add((i + 1).ToString)
-
Next
-
End Sub
-Frinny