ASP Paging Code

Source: Internet
Author: User
Tags prev

For a long time, I found the search in the way I wanted my results page, but now the problem is it does ' NT show all the thumb right all the people without the thumb links are mostly right.
Who can help me. O and for Sems he got a database connection

<%
Option Explicit
' Declare variables
Dim currpage, Pagelen, Lastnumber, Pagerem, Pageten
Dim connection, Recordset, sSQL, sConnString, next10, PREV10, P
Dim Rsprevpage, Rsnextpage, start
' Get the current page ' 's ' User is ', if it ' s the They
' Visit and the variable ' pageno ' is empty, then ' currpage ' gets set to 1
' Else the current page variable ' currpage ' are set to the page number requested
If IsEmpty (Request.QueryString ("PageNo")) Then
Currpage = 1
Else
Currpage = Cint (Request.QueryString ("PageNo"))
End If

' The two functions below return the next and Prev page number
Function getNext10 (num)
Pagelen = Len (num)
If Pagelen = 1 Then
Next10 = 10
Else If pagelen>1 Then
Pagerem = 10
Pageten = Right (num, 1)
next10 = num + pagerem-pageten
End If
End If
GetNext10 = next10
End Function

Function getPrev10 (num)
Pagelen = Len (num)
If Pagelen = 1 Then
PREV10 = 1
Else If Pagelen>1 Then
Lastnumber = Right (num, 1)
PREV10 = num-lastnumber-10
End If
End If
If prev10 = 0 Then
PREV10 = 1
End If
GETPREV10 = prev10
End Function

' Create an instance of the ADO connection and Recordset object
Set Connection = Server.CreateObject ("ADODB. Connection ")
Set Recordset = Server.CreateObject ("ADODB.") Recordset ")

' Define the connection string
sconnstring = "Driver={microsoft Access DRIVER (*.mdb)};" & _
"Dbq=" & Server.MapPath ("Db.mdb") & ";"

' Define our SQL variable
Ssql= "SELECT * from Tbl_content WHERE plantnaam like ' a% ' ORDER by [Plantnaam] ASC"

' Open an active connection
Connection.Open sconnstring

' Next set ' location of the recordset to the client side
Recordset.cursorlocation = 3

' Execute the SQL and return our recordset
Recordset.Open sSQL, sConnString
' pagesize is used to set the number of records that would be
' displayed on each page. For our purposes the records is what we want.
Recordset.pagesize = 14
%>

<body>
<%
' Get the ' next and Prev page number
next10 = getNext10 (currpage)
PREV10 = GETPREV10 (currpage)

' The next 2 lines setup The page number for the ' previous ' and ' Next ' links
Rsprevpage = CurrPage-1
Rsnextpage = currpage + 1

' Find out ' the number of pages returned in the recordset
' If ' Next10 page number is greater than the recordset page count
' Then set Next10 to the recordset PageCount
If Next10 > Recordset.pagecount Then
Next10 = Recordset.pagecount
End If

' The variable start determines where to start the page number navigation
' I.e, 1, on.
If prev10 = 1 and Next10-1 < Then
Start = 1
Else
Start = next10-14
If Right (start, 1) > 0 Then
Start = replace (start, right (start, 1), "0")
Start = start + 14
End If
End If

' This checks to make sure so there is more than one page of results
If recordset.pagecount > 1 Then
' Work out whether to show the Previous ' << '
If currpage > 1 Then
Response.Write ("<a href=") paging.asp? Pageno= "& Prev10 &" "><<</a>"
End If
' Work out whether to show the Previous link ' < '
If not rsprevpage = 0 Then
Response.Write ("<a href=") paging.asp? Pageno= "& Rsprevpage &" "><</a>"
End If

' Loop through the page number navigation using P as our loopcounter variable
For P = start to Next10

If not P = Currpage Then
Response.Write ("<a href=") paging.asp? Pageno= "& P &" ">" & P & "</a>"
Else
' Don ' t hyperlink the current page number
Response.Write ("<b>" & P & "</b>")
End If
Next
' This does the same as the ' previous ' link, but for the ' next ' link
If not rsnextpage > Recordset.pagecount Then
Response.Write ("<a href=") paging.asp? Pageno= "& Rsnextpage &" ">></a>"
End If

' Work out whether to show the Next ' >> '
If not Next10 = Recordset.pagecount Then
Response.Write ("<a href=") paging.asp? Pageno= "& Next10 &" ">>></a><br><BR>"
End If
End If


' If there are no records
If recordset.eof Then
Response.Write "No Records to display"

Else
' This moves the record pointer to the '
Recordset.absolutepage = Currpage

' The below loop would loop until all the records's current page have been
' Displayed or it has reached the end of the recordset
Do Until recordset.absolutepage <> currpage OR recordset.eof

' For our purposes our database has just 3 fields:
' An ' ID ' (AutoNumber field), ' SiteName ' (TextField) and ' URL ' (Memofield)
' Can change this according to your database and table fields
Response.Write "<a href=" & Recordset ("Link") & ">" & Recordset ("Plantnaam") & </A><BR&G T;<br> "
Response.Write "

Recordset.movenext
Loop

End If

' The next 2 lines setup The page number for the ' previous ' and ' Next ' links
Rsprevpage = CurrPage-1
Rsnextpage = currpage + 1

' Find out ' the number of pages returned in the recordset
' If ' Next10 page number is greater than the recordset page count
' Then set Next10 to the recordset PageCount
If Next10 > Recordset.pagecount Then
Next10 = Recordset.pagecount
End If

' The variable start determines where to start the page number navigation
' I.e, 1, on.
If prev10 = 1 and Next10-1 < 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

' This checks to make sure so there is more than one page of results
If recordset.pagecount > 1 Then
' Work out whether to show the Previous ' << '
If currpage > 1 Then
Response.Write ("<a href=") paging.asp? Pageno= "& Prev10 &" "><<</a>"
End If
' Work out whether to show the Previous link ' < '
If not rsprevpage = 0 Then
Response.Write ("<a href=") paging.asp? Pageno= "& Rsprevpage &" "><</a>"
End If

' Loop through the page number navigation using P as our loopcounter variable
For P = start to Next10

If not P = Currpage Then
Response.Write ("<a href=") paging.asp? Pageno= "& P &" ">" & P & "</a>"
Else
' Don ' t hyperlink the current page number
Response.Write ("<b>" & P & "</b>")
End If
Next
' This does the same as the ' previous ' link, but for the ' next ' link
If not rsnextpage > Recordset.pagecount Then
Response.Write ("<a href=") paging.asp? Pageno= "& Rsnextpage &" ">></a>"
End If

' Work out whether to show the Next ' >> '
If not Next10 = Recordset.pagecount Then
Response.Write ("<a href=") paging.asp? Pageno= "& Next10 &" ">>></a>"
End If
End If

' Close ' Recordset and Connection object
Recordset.close
Set Recordset = Nothing
Connection.close
Set Recordset =nothing
%>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.