I take that no one has heard of RS Paging?
Here is the code I use:
Code:
if isempty(request.querystring("PageNo")) OR request.querystring("PageNo") = "" then
CurrPage = 1
else
CurrPage = cint(request.querystring("PageNo"))
end if
Set news = Server.CreateObject("ADODB.Recordset")
news.CursorLocation = 3
news.Open "SQL", connectionString
news.PageSize = 3 ' Number of records per page news.AbsolutePage = CurrPage
DO UNTIL news.AbsolutePage <> CurrPage OR news.EOF
' Loop records here
news.MoveNext
LOOP
RSPrevPage = CurrPage -1
RSNextPage = CurrPage + 1
next10 = getNext10(currPage)
prev10 = getPrev10(currPage)
if Next10 > news.PageCount then
next10 = news.PageCount
end if
if prev10 = 1 AND next10 - 1 < 10 then
start = 1
else
start = Next10 - 10
if right(start, 1) > 0 then
start = replace(start, right(start, 1), "0")
start = start + 10
end if
end if
if news.PageCount > 1 then
if next10 > 10 then
response.write("<p class=""para1""><a href=""" & request.servervariables("SCRIPT_NAME") & "?PageNo=" & Prev10 & " &searchText=" & server.urlencode(request("searchtext")) & """ " & linkStyle & "><<</a> ")
end if
if not RSPrevPage = 0 then
response.write("<a href=""" & request.servervariables("SCRIPT_NAME") & "?PageNo=" & RSPrevPage & "&searchText=" & server.urlencode(request("searchtext")) & """ " & linkStyle & "><</a> ")
end if
for P = start to Next10
if not P = CurrPage then
response.write("<a href=""" & request.servervariables("SCRIPT_NAME") & "?PageNo=" & P & "&searchText=" & server.urlencode(request("searchtext")) & """ " & linkStyle & ">" & P & "</a> ")
else
response.write(" <b>" & P & " </b>")
end if
Next
if not RSNextPage > news.PageCount then
response.write("<a href=""" & request.servervariables("SCRIPT_NAME") & "?PageNo=" & RSNextPage & "&searchText=" & server.urlencode(request("searchtext")) & """ " & linkStyle & ">></a> ")
end if
if not Next10 = news.PageCount then
response.write(" <a href=""" & request.servervariables("SCRIPT_NAME") & "?PageNo=" & Next10 & "&searchText=" & server.urlencode(request("searchtext")) & """ " & linkStyle & ">>></a>")
end if
end if
SET news = nothing
There is a little crap there that I'm sure you can take out, if you can't I'll do it tomorrow.
Now the two functions (getNext10 & getPrev10):
Code:
function getNext10(num)
pageLen = len(num)
if pageLen = 1 then
next10 = 10
elseif pageLen = 2 then
pageRem = 10
pageTen = right(num, 1)
next10 = num + pageRem - pageTen
elseif pageLen > 2 then
pageRem = 10
pageTen = right(num, 1)
next10 = num + pageRem - pageTen
end if
getNext10 = next10
end function
function getPrev10(num)
pageLen = len(num)
if pageLen = 1 then
prev10 = 1
elseif pageLen = 2 then
firstDig = left(num, 1)
secondDig = right(num, 1)
prev10 = num - secondDig - 10
elseif pageLen > 2 then
firstDig = right(num, 2)
secondDig = right(num, 1)
prev10 = num - secondDig - 10
end if
if prev10 = 0 then
prev10 = 1
end if
getPrev10 = prev10
end function
Hope that helps, if you need help with it, let me know.
Bookmarks