By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,867 Members | 1,981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,867 IT Pros & Developers. It's quick & easy.

asp paging with numbers help?

P: 14
I'm trying to setup paging with numbers in the middle of Previous and Next buttons. I found a script I like but i have one issue with it. Please help many thanks in advance.

Here the script I found. It uses iNumPerPage for how many records your showing on each page. So if I put 10 per page then it shows ten numbers which is what I want. But I want to show 25 per page it show 25 numbers I only want to show ten numbers at a time. Can you please help me to get this scripted working or if you have an already working script can you please send it to me. Many Thanks!!!!!!

Expand|Select|Wrap|Line Numbers
  1. Sub PrintRecordsetNav( iNumPerPage, adodbConnection, adodbCommand, sTable, sURL, sQuerystring )
  2.  
  3.     Dim iTtlNumItems, iDBLoc, sSqlTemp, iTtlTemp
  4.     Dim iDBLocTemp, sURLBeg, iA, iB, x, iTemp, rsObj
  5.  
  6.     iDBLoc = CInt(Request("iDBLoc"))
  7.     iTtlNumItems = CInt(Request("iTtlNumItems"))
  8.     ' Get ttl num of items from the database if it's not already in the QueryString
  9.     if (iTtlNumItems = 0) then
  10.         Set rsObj = Server.CreateObject("ADODB.Recordset")
  11.         sSqlTemp = "SELECT COUNT(*) FROM " & sTable
  12.         adodbCommand.CommandText = sSqlTemp
  13.         rsObj.Open adodbCommand
  14.         If Not(rsObj.EOF) Then
  15.             iTtlNumItems = rsObj(0)
  16.         End If
  17.         rsObj.Close
  18.         Set rsObj = Nothing
  19.     end if
  20.     iTtlTemp = iTtlNumItems \ iNumPerPage    ' this is the number of numbers overall (use the "\" to return int)
  21.     iDBLocTemp = iDBLoc \ iNumPerPage        ' this is which number we are currently on (use the "\" to return int)
  22.     If (sQuerystring <> "") Then
  23.         sURLBeg = "<a href = """ & sURL & "?" & sQuerystring & "&iTtlNumItems=" & iTtlNumItems & "&iDBLoc="
  24.     Else
  25.         sURLBeg = "<a href = """ & sURL & "?iTtlNumItems=" & iTtlNumItems & "&iDBLoc="
  26.     End If
  27.  
  28.     '***** BEGIN DISPLAY *****
  29.     ' Print the "Previous"
  30.     if (iDBLoc <> 0) then
  31.         Response.Write sURLBeg & (iDBLoc - iNumPerPage) & """>Previous</a>  "
  32.     end if
  33.     ' Print the <<
  34.     if (iDBLocTemp >= iNumPerPage) then
  35.         Response.Write sURLBeg & (( iDBLocTemp \ iNumPerPage ) * iNumPerPage ^ 2) - (iNumPerPage * 9) & """><<</a> "
  36.     end if
  37.  
  38.     ' Print the numbers in between. Print them out in sets of 10.
  39.     iA = ( iDBLocTemp \ iNumPerPage ) * iNumPerPage
  40.     iB = ( iDBLocTemp \ iNumPerPage ) * iNumPerPage + iNumPerPage
  41.     for x = iA to iB
  42.         iTemp = (x * iNumPerPage)
  43.         if (iTemp < iTtlNumItems) then    ' takes care of extra numbers after the overall final number
  44.             if (iDBLoc = iTemp) then
  45.                 Response.Write " <b>[" & x+1 & "]</b>"
  46.             else
  47.                 Response.Write " " & sURLBeg & (x * iNumPerPage) & """>" & x+1 & "</a>"
  48.             end if
  49.         else
  50.             exit for
  51.         end if
  52.     next
  53.  
  54.     ' Print the >>
  55.     if (iTtlTemp > iDBLocTemp) then
  56.         if ((iDBLocTemp + iNumPerPage) <= iTtlTemp) then
  57.             Response.Write " " & sURLBeg & (( iDBLocTemp \ iNumPerPage ) * iNumPerPage + iNumPerPage ) * iNumPerPage & """>>></a> "
  58.         end if
  59.     end if
  60.     ' Print the "Next"
  61.     if ((iDBLoc + iNumPerPage) < iTtlNumItems) then
  62.         Response.Write "  " & sURLBeg & (iDBLoc + iNumPerPage) & """>Next</a>"
  63.     end if
  64.     '***** END DISPLAY *****
  65.  
  66. End Sub
  67.  
Nov 23 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.