RSS
 

Recordset Paging With .GetRows()

10 Dec

I constantly use a .GetRows() array when displaying a recordset from a database.  However, I found that I needed to be able to page the records ont he page, so that so many records won’t display all at once potentially crashing the page.

Here is a function that I use to display a Google like recordset paging system.

  1. <%
  2. ‘Usage = Response.Write(PagingLinks(TheArrayNameFromRecordset, HowManyPerPage, URLOfThePageWeAreOn, 1stLinkDisplay, PrevLinkDisplay, NextLinkDisplay, LastLinkDisplay, StartingPage#Display, EndingPage#Display))
  3. Function PagingLinks(ByVal strArrName, ByVal strNumPerPage, ByVal strPageName, ByVal strFirst, ByVal strPrev, ByVal strNext, ByVal strLast, ByVal iStart, ByVal iStop)
  4.         PagingLinks = ""
  5.         iStart = Request.QueryString("s")
  6.         iOffset = Request.QueryString("o")
  7.         If Not IsNumeric(iStart) Then
  8.                 iStart = 0
  9.         Else
  10.                 iStart = CLng(iStart)
  11.         End If
  12.         If Not IsNumeric(iOffset) Then
  13.                 iOffset = strNumPerPage
  14.         Else
  15.                 iOffset = CLng(iOffset)
  16.         End If
  17.         If UBound(strArrName, 2) < strNumPerPage Then
  18.                 iRows = (UBound(strArrName,2) + 1)
  19.         Else
  20.                 iRows = UBound(strArrName,2)
  21.         End If
  22.         If iRows > (iOffset + iStart) Then
  23.                 iStop = iOffset + iStart – 1
  24.         Else
  25.                 iStop = iRows
  26.         End If
  27.         If iStop > iRows – iOffset Then
  28.                 iStop = iStop – 1
  29.         End If
  30.         If Not(IsNumeric(iOffset)) Then iOffset = 1
  31.         pages = RoundUp(iRows / iOffset)
  32.         pgNum = RoundUp(iStart / iOffset) + 1
  33.         PagingLinks = PagingLinks & "<a href="" strpagename="" &s="0&o=&quot;" ioffset="" &="">" & strFirst & "</a> "
  34.         If iStart > 0 Then
  35.                 PagingLinks = PagingLinks & "<a href="" strpagename="" &="" &s=" & iStart – iOffset & " &o=" & iOffset & ">" & strPrev & "</a> "
  36.         End If
  37.         Dim MaxPagesToShow, MaxLBound, MaxUBound
  38.         MaxPagesToShow = 10
  39.         MaxLBound = pgNum – Int(MaxPagesToShow/2)
  40.         If MaxLBound < 1 Then MaxLBound = 1
  41.         MaxUBound = MaxLBound + MaxPagesToShow
  42.         If MaxUBound > pages Then
  43.                 MaxUBound = pages
  44.                 MaxLBound = MaxUBound – MaxPagesToShow
  45.         End If
  46.         If MaxLBound < 1 Then MaxLBound = 1
  47.         If (iRows – iOffset) < 0 Then
  48.                 l = 0
  49.         Else
  50.                 l = (iRows – iOffset)
  51.         End If
  52.         For z = MaxLBound To MaxUBound
  53.                 pgOffset = z * iOffset – iOffset
  54.                 If z = pgNum Then
  55.                         PagingLinks = PagingLinks & ("<b>" & z & "</b> ")
  56.                 Else
  57.                         PagingLinks = PagingLinks & ("<a href="" strpagename="" &="" &s=" & pgOffset & " &o=" & iOffset & ">" & z & "</a> ")
  58.                 End If
  59.         Next
  60.         If iStop + 1 < iRows Then
  61.                 PagingLinks = PagingLinks & "<a href="" strpagename="" &="" &s=" & iStart + iOffset & " &o=" & iOffset & ">" & strNext & "</a> "
  62.         End If
  63.         PagingLinks = PagingLinks & "<a href="" strpagename="" &="" &s=" & l & " &o=" & iOffset & ">" & strLast & "</a><br>"
  64. End Function
  65. %>
 
 

Tags: , ,

Leave a Reply

 
 
 

Optimized by SEO Ultimate