Connecting Tech Pros Worldwide Help | Site Map

Cutomize the logic for Paging

Familiar Sight
 
Join Date: Apr 2008
Posts: 147
#1: 2 Weeks Ago
Hi all,

Can anybody tell me how to cutomize the logic for Paging?

I designed the page with control dataGrid - AllowPaging is the property that perform Paging in the DataGrid.Can anybody tell me how can I implement this logic without using "AllowPaging"property ?

Thanks!
maliksleo's Avatar
Member
 
Join Date: Feb 2009
Location: Islamabad, Pakistan
Posts: 115
#2: 1 Week Ago

re: Cutomize the logic for Paging


hi
just count the records and devide them on the page size you want to show. then using javascript you can perform the paging. Alot of material available on this issue on internet. Secondly you can perform paging through your code as well instead of javascript.
Define the page size and store the page number in some variable and add and subtract the values on your paging buttons click events.

maliksleo
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#3: 1 Week Ago

re: Cutomize the logic for Paging


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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub PreviousPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PreviousPage.Click
  2.   If MyGridView.PageIndex > 0 Then
  3.     MyGridView.PageIndex = MyGridView.PageIndex - 1
  4.     'QuickSelectPageList is the DropDownList that lets the user jump between pages
  5.     QuickSelectPageList.ClearSelection()
  6.     QuickSelectPageList.Items(MyGridView.PageIndex).Selected = True
  7.   End If
  8. End Sub
Here is an example of code that I use to populate the DropDownList that lets the user jump between pages:
Expand|Select|Wrap|Line Numbers
  1. Private Sub InitializeGridViewQuickSelectDropDownList()
  2.   Dim numpages = MyGridView.PageCount
  3.   QuickSelectPageList.Items.Clear()
  4.   'Populating the Quick Page Select drop down list
  5.   For i As Integer = 0 To numpages - 1
  6.     QuickSelectPageList.Items.Add((i + 1).ToString)
  7.   Next
  8. End Sub
-Frinny
Reply