PAgination by grouping pages

Posted on 2004-09-09
Last Modified: 2010-04-17
Hi I am looking for solution for Pagination by grouping. Currently I have a form from which the user can select the  number of rows or records he wants to see. This information is passed to another form where the total numbers of records is got and then divided by the number of rows passed to get the total number of pages and is shown as strvariable  For ex if the number of records is 1000 and number of rows passed is 25 there will be 40 pages with links to all and next and previous links. But I want the pages to be shown in groups of 10. If there are more than ten pages the first 10 will be shown as 1,2,3,4,5,6,7,8,9,10..>>>Next 10 and so on. The links to previous should be active. Can someone help?

Question by:PNKJ
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 32

Expert Comment

ID: 12022684
so, which language are you using ?

Author Comment

ID: 12025517

Accepted Solution

Freak4VB earned 500 total points
ID: 12263381
Hi There !

Am posting a code that contains an exact implementation of this logic you are trying to build in. Had to write this sometime back for an application. The code is not too complicated (though trust me the algo is !!).
C_NEXTLINK and C_... are all constants declared in a class called OtherConstants so u needn't worry abt them, just replace them wit >> or << or watever !

OtherConstants.C_MAXPAGES = 10 that is the maximum number of pages u want the system to display at once. Keep on changing it to whatever value u want and everythin would still work !!

 Dim lsDelimiter As String
    Dim liLoop As Integer
    Dim lsHyperLink As String
    Dim liPageCount As Integer = 1
    Dim lsPrevLink As String = ""
    Dim lsNextLink As String = ""
    Dim liPrevPage As Integer = 0
    Dim liNextPage As Integer = 0
    Dim liQuotent As Integer = 0
    Dim liRemainder As Integer = 0
    Dim liTemp As Integer = 0
    Dim liMaxPages As Integer = OtherConstants.C_MAXPAGES


      'General Rules
      '1. Previous link would come only if current page is > MaxNumberofAllowedPages and the user is not viewing a page in the first batch of pages
      '2. Next link would come if the total number of pages is >MaxNumberofAllowedPages and totalnumberofpages - currentpage > MaxNumberofAllowedPages

      lsDelimiter = "<img src='images/gifDotedLine.gif' hspace='3' align='absbottom'>"

      'find if the Prev link is to be rendered or not and make the string if it is to be rendered
      If miCurrentPage > liMaxPages Then
        'Find the previous page that the Previous link should point to

        liQuotent = Math.DivRem(miCurrentPage, liMaxPages, liRemainder)
        If liRemainder = 0 Then
          liPrevPage = miCurrentPage - liMaxPages
          liPrevPage = miCurrentPage - liRemainder
        End If

        'Render previous link
        lsHyperLink = "&nbsp;<a href = ""javascript:togglePage('" & liPrevPage & "')"""
        lsHyperLink = lsHyperLink & ">" & OtherConstants.C_PREVLINK & "</a>&nbsp;"
        lsPrevLink = lsHyperLink
      End If

      liQuotent = 0
      liRemainder = 0
      'Find if the Next LInk is required and calculate and render the string if it is required

      If miTotalPages > liMaxPages Then
        liQuotent = Math.DivRem(miTotalPages, liMaxPages, liRemainder)
        If liRemainder = 0 Then
          liTemp = (liQuotent - 1) * liMaxPages + 1
          liTemp = (liQuotent * liMaxPages) + 1
        End If

        If miCurrentPage < liTemp Then
          'Next link required, calculate and generate the string
          liNextPage = liPrevPage + liMaxPages + 1
          lsHyperLink = "&nbsp;<a href = ""javascript:togglePage('" & liNextPage & "')"""
          lsHyperLink = lsHyperLink & ">" & OtherConstants.C_NEXTLINK & "</a>"
          lsNextLink = lsHyperLink
        End If

      End If
      liTemp = 0
      'Now we will calculate the boundaries of our For Loop
      'Lower bound is always liPrevPage+1
      'Upper bound will be lower of liPrevPage+maxpages and miTotalPages

      liTemp = Math.Min(liPrevPage + liMaxPages, miTotalPages)
      For liLoop = liPrevPage + 1 To liTemp
        If liLoop <> miCurrentPage Then
          lsHyperLink = "<a href = ""javascript:togglePage('" & liLoop & "')"""
          lsHyperLink = lsHyperLink & ">" & liLoop & "</a>"

          lsHyperLink = liLoop
        End If
        If liLoop <> liTemp Then
          lsHyperLink = lsHyperLink & lsDelimiter
        End If
        msPageNum = msPageNum & lsHyperLink

      'Append the prev next srtings
      If lsNextLink.Trim <> "" Then
        lsNextLink = lsDelimiter & lsNextLink
      End If
      If lsPrevLink <> "" Then
        lsPrevLink = lsPrevLink & lsDelimiter
      End If
      msPageNum = "Page: " & lsPrevLink & msPageNum & lsNextLink

    Catch ex As Exception
      Throw ex
    End Try

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question