Detailed explanation of ASP paging technology (prev/next page)

Source: Internet
Author: User
Tags prev

First, let's understand the principle.

Home:

This use of the current page is the first page when discriminant, if the current for the first page (that is, home), then display the first two words, no link, otherwise provide direct jump to the homepage of the link.

Previous page:

When you are currently on the first page, the link fails, and in turn, links to the previous page in front, where you use: <%=curpage-1%>, that is, by subtracting 1 from the current number of pages and getting the previous page.

Next page:

Here you need to use rs.pagecount this property to compare, if the total number of pages is less than the current page plus 1 of the value, which indicates that this is the next, the link will be invalidated, otherwise linked to the next page.

Last:

As with the function on the next page, the link is invalidated when the last page is found, otherwise the current page is specified as Rs.pagecount (total pages).

Knowing the above things, we can do the paging code according to the requirement.


On the page where you want the page number to appear:

Instance 1

The code is as follows Copy Code

Page=cint (Request ("page") ' page is the parameter of the page number in the URL
Querys= "..." ' Define additional parameters for the URL


Rs. Pagesize=30 ' per page number, set yourself
Dim Pagecount=rs. PageCount
Rs. Absolutepage=pageno

If Pagecount>1 Then
Response.Write ("Pagination:")
Outpages pagecount,page ' here ' to show page numbers, function see after
Response.Write "<br><br>"
End If


Dim showcount=0
Do while (not rs.eof and Showcount<rs. PageSize)
Show each piece of content
Showcount=showcount+1
Rs.movenext
Loop

' The following is a function to display page numbers, which can be placed in a single file:

The code is as follows Copy Code

Sub Outpages (Pagecount,curpage)

Yyy=int ((curpage-1)/10)
Startno=yyy*10+1
Endno=startno+10-1


If Startno<1 then startno=1
If Endno>pagecount then Endno=pagecount

Response.Write "<b>"

If Startno>1 Then
Response.Write "&nbsp;&nbsp;<a target=_top href=?" &querys& "&page=" & (startno-10) & "><<</a>&nbsp;&nbsp;"
End If


For J=startno to Endno
If J=page Then
Response.Write "" &j& "&nbsp;&nbsp;"
Else
Response.Write "<a target=_top href= '"
Response.Write "?" &querys& "&page=" &j
Response.Write "' >[" &j& "]</a>&nbsp;&nbsp;"
End If
Next


If Pagecount>endno Then
Response.Write "&nbsp;&nbsp;<a target=_top href=?" &querys& "&page=" & (endno+1) & ">>></a>"
End If

Response.Write "</b>"

End Sub

Instance 2

The code is as follows Copy Code

<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open ("Driver=driver do Microsoft Access (*.mdb);" uid=admin;pwd=;d bq= "&server.mappath (" 1.mdb "))
Set Rs=server.createobject ("Adodb.recordset")
Sql= "SELECT * FROM Student"
Rs.Open sql,conn,3
Rs.pagesize=20
If Request ("page") <> "then
Epage=cint (Request ("page")
If Epage<1 then epage=1
If Epage>rs.pagecount then Epage=rs.pagecount
Else
Epage=1
End If
Rs.absolutepage=epage
%>
<table border= "0" cellpadding= "0" cellspacing= "1" bgcolor= "#0000FF" width= "80%" align= "Center" >
<tr bgcolor= "#FFFFFF" align= "Center" >
<th><%=rs (0). Name%></th><th><%=rs (1). Name%></th><th><%=rs (2). Name %></th>
</tr>
<%
For I=0 to Rs.pagesize-1
If Rs.bof or rs.eof then exit for
%>
<tr bgcolor= "#FFFFFF" align= "Center" >
<td><%=rs (0). Value%></td><td><%=rs (1). Value%></td><td><%=rs (2). Value%></td>
</tr>
<%
Rs.movenext ()
Next
%>
</table>
<p align= "center" >
<a href= "" > Home </a>&nbsp;
<a href= "index.asp?page=<%=epage-1%>" > previous page </a>&nbsp;
<a href= "index.asp?page=<%=epage+1%>" > next page </a>&nbsp;
<a href= "index.asp?page=<%=rs.pagecount%>" > Last </a>
</p>
<p align= "Center" > now is <%=epage%> page altogether has <%=rs.pagecount%> page </p>
<%
Conn.close ()
%>


The table has three fields, indicating that for student the others do not need to be changed, the pagesize can also be changed, if the record is less.

There are several key commands for implementing pagination in ASP

The code is as follows Copy Code
Rs. Pagesize=30 ' per page number, set yourself
Dim Pagecount=rs. PageCount
Rs. Absolutepage=pageno

These three are our ASP in the paging must be used, otherwise your pagination will not be successful Oh, this is also the ASP's short board to make people feel the way the mind.

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.