Cutomize the logic for Paging

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madankarmukta
    Contributor
    • Apr 2008
    • 308

    #1

    Cutomize the logic for Paging

    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"pr operty ?

    Thanks!
  • maliksleo
    New Member
    • Feb 2009
    • 115

    #2
    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

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      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 "PreviousPa ge" link button click event:
      Code:
      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:
      Code:
      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

      Comment

      Working...