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.
-
<%
-
‘Usage = Response.Write(PagingLinks(TheArrayNameFromRecordset, HowManyPerPage, URLOfThePageWeAreOn, 1stLinkDisplay, PrevLinkDisplay, NextLinkDisplay, LastLinkDisplay, StartingPage#Display, EndingPage#Display))
-
Function PagingLinks(ByVal strArrName, ByVal strNumPerPage, ByVal strPageName, ByVal strFirst, ByVal strPrev, ByVal strNext, ByVal strLast, ByVal iStart, ByVal iStop)
-
PagingLinks = ""
-
iStart = Request.QueryString("s")
-
iOffset = Request.QueryString("o")
-
If Not IsNumeric(iStart) Then
-
iStart = 0
-
Else
-
iStart = CLng(iStart)
-
End If
-
If Not IsNumeric(iOffset) Then
-
iOffset = strNumPerPage
-
Else
-
iOffset = CLng(iOffset)
-
End If
-
If UBound(strArrName, 2) < strNumPerPage Then
-
iRows = (UBound(strArrName,2) + 1)
-
Else
-
iRows = UBound(strArrName,2)
-
End If
-
If iRows > (iOffset + iStart) Then
-
iStop = iOffset + iStart – 1
-
Else
-
iStop = iRows
-
End If
-
If iStop > iRows – iOffset Then
-
iStop = iStop – 1
-
End If
-
If Not(IsNumeric(iOffset)) Then iOffset = 1
-
pages = RoundUp(iRows / iOffset)
-
pgNum = RoundUp(iStart / iOffset) + 1
-
PagingLinks = PagingLinks & "<a href="" strpagename="" &s="0&o="" ioffset="" &="">" & strFirst & "</a> "
-
If iStart > 0 Then
-
PagingLinks = PagingLinks & "<a href="" strpagename="" &="" &s=" & iStart – iOffset & " &o=" & iOffset & ">" & strPrev & "</a> "
-
End If
-
Dim MaxPagesToShow, MaxLBound, MaxUBound
-
MaxPagesToShow = 10
-
MaxLBound = pgNum – Int(MaxPagesToShow/2)
-
If MaxLBound < 1 Then MaxLBound = 1
-
MaxUBound = MaxLBound + MaxPagesToShow
-
If MaxUBound > pages Then
-
MaxUBound = pages
-
MaxLBound = MaxUBound – MaxPagesToShow
-
End If
-
If MaxLBound < 1 Then MaxLBound = 1
-
If (iRows – iOffset) < 0 Then
-
l = 0
-
Else
-
l = (iRows – iOffset)
-
End If
-
For z = MaxLBound To MaxUBound
-
pgOffset = z * iOffset – iOffset
-
If z = pgNum Then
-
PagingLinks = PagingLinks & ("<b>" & z & "</b> ")
-
Else
-
PagingLinks = PagingLinks & ("<a href="" strpagename="" &="" &s=" & pgOffset & " &o=" & iOffset & ">" & z & "</a> ")
-
End If
-
Next
-
If iStop + 1 < iRows Then
-
PagingLinks = PagingLinks & "<a href="" strpagename="" &="" &s=" & iStart + iOffset & " &o=" & iOffset & ">" & strNext & "</a> "
-
End If
-
PagingLinks = PagingLinks & "<a href="" strpagename="" &="" &s=" & l & " &o=" & iOffset & ">" & strLast & "</a><br>"
-
End Function
-
%>
Link to this post!












