Recently a lot of friends to consult the problem of pagination, I will send a complete page of my own program, I hope to help you

Source: Internet
Author: User
Program | pagination | problem <%
Set Rs=createobject ("Adodb.recordset")
Rs.Open "SELECT * from table", conn,1,1
If Rs.eof Then
Response.Write "No records!"
Else
If not IsEmpty (Request ("page") Then
Currentpage=cint (Request ("page")
Else
Currentpage=1
End If

rs.pagesize=10
Totalput=rs.recordcount
Totalpage=rs.pagecount
Maxperpage=rs.pagesize
If Currentpage<1 Then
Currentpage=1
End If
If Currentpage>totalpage Then
Currentpage=totalpage
End If
If Currentpage=1 Then
Showhead ' pagination results display head, such as a total of several pages of records and stuff.
Showcontent ' Show this page recordset
Showfoot ' distribution results show tail, such as links to other pages
Else
if (currentPage-1) *maxperpage<totalput Then
Rs.move (currentPage-1) *maxperpage
Showhead
Showcontent
Showfoot
Else
End If
End If
End If

Sub Showcontent
Dim i,j
I=1
Do as not (rs.eof or ERR)
%>
' Enter the single record display mode here
<%
If I>=maxperpage then Exit Do
I=i+1
Rs.movenext
Loop
End Sub

Link code to other pages:
1, link to the previous page, the next page, home and last
<%
If currentpage <> 1 Then
Response.Write "<a href=show.asp>[first page]</a>"
Response.Write "<a href=show.asp?" Page= "& (currentPage-1) &" >[prev]</a> "
End If
If currentpage <> Rs. PageCount Then
Response.Write "<a href=show.asp?" Page= "& (currentpage+1) &" >[next]</a> "
Response.Write "<a href=show.asp?" Page= "& Totalpage &" >[last page]</a> "
End If
%>
2, jump to any one of the pages
<form action= "show.asp" method= "get" align= "right" style= "margin-top:0px"; margin-bottom:0px ">
<%for I=1 to N
Response.Write "<option value=" & I
If Currentpage=i Then
Response.Write "Selected"
End If
Response.Write ">" & I & "</option>"
Next
Response.Write "</select>"
Response.Write "<input class=buttonface type= ' submit ' value= ' Go ' style= ' font-family: Song body; Font-size:8pt;height:19 ' > '
%>
3, link to the beginning of the current page after 10 pages
<%
For J=currentpage+1 to Currentpage+10
If J>totalpage then Exit do%>
<a href= "Show.asp?page=<%=j%>" ><%=j%></a>
<%
Next
%>



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.