Solved

PAgination by grouping pages

Posted on 2004-09-09
5
269 Views
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?

Thanks
0
Comment
Question by:PNKJ
5 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 12022684
so, which language are you using ?
0
 

Author Comment

by:PNKJ
ID: 12025517
vbscript
0
 
LVL 2

Accepted Solution

by:
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

    Try

      '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
        Else
          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
        Else
          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>"

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

      '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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article will show, step by step, how to integrate R code into a R Sweave document
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now