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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression

630 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