2 column pagination display (with the form shown in front page, back page)

Source: Internet
Author: User
Tags error handling rowcount servervariables
Display form:
ID1 NAME | ID2 NAME
1 JULIET | 2 Palyboy
3 BABY | 4 TOM
5 LENA | 6 Jery
>> first previous next last page: 1/4 6 Records/page Total record number: 25
Code:
<!--page1.asp-->
<!--#include file= "conn.asp"-->
<body bgcolor= "#FFFFFF" text= "#000000" >
<table width= "60%" border= "1" align= "Center" >
<%
Dim rs
Dim sql
Msg_per_page = 4 ' defines the number of record bars per page
Set rs = Server.CreateObject ("Adodb.recordset")
sql = "SELECT * from page ORDER by id" "Change to your own SQL statement
Rs.cursorlocation = 3 ' uses client-side cursors to improve efficiency

Rs.pagesize = Msg_per_page ' defines the number of records per page for a paging recordset
Rs.Open sql,conn,0,1

If Err.number<>0 then ' error handling
Response.Write "Database operation failed:" & Err.Description
Err.Clear
Else
If not (rs.eof and RS.BOF) Then ' detects whether the recordset is empty
Totalrec = RS. RecordCount ' Totalrec: Total number of record strips
If rs.recordcount mod msg_per_page = 0 Then ' calculates total number of pages, RecordCount: Total Records of data
n = Rs.recordcount\msg_per_page ' N: Total pages
Else
n = rs.recordcount\msg_per_page+1
End If

CurrentPage = Request ("page") ' CurrentPage: Current page
If currentpage <> "" Then
CurrentPage = CInt (currentpage)
If currentpage < 1 Then
CurrentPage = 1
End If
If Err.Number <> 0 Then
Err.Clear
CurrentPage = 1
End If
Else
CurrentPage = 1
End If
If Currentpage*msg_per_page > Totalrec and Not ((currentpage-1) *msg_per_page < Totalrec) Then
Currentpage=1
End If
Rs.absolutepage = CurrentPage ' AbsolutePage: Set pointer to start of a page
RowCount = Rs.pagesize ' pagesize: Sets the number of data records per page

Dim i
Dim k
%>
&LT;TR align= "center" valign= "Middle" >
&LT;TD width= "25%" >ID1</td>
&LT;TD width= "25%" >name1</td>
&LT;TD width= "25%" >ID2</td>
&LT;TD width= "25%" >name2</td>
</tr>
<%do while not rs.eof and rowcount > 0%>
&LT;TR align= "center" valign= "Middle" >
&LT;TD width= "25%" ><%=rs ("id")%></td>
&LT;TD width= "25%" ><%=rs ("testname")%></td>
<td>
<%
Rowcount=rowcount-1
Rs. MoveNext
If not Rs. EOF Then
%>
&LT;%=RS ("id")%>
</td>
&LT;TD width= "25%" ><%=rs ("testname")%></td>
</tr>
<%
Rowcount=rowcount-1
Rs. MoveNext
Else
Response.Write "</td><td> </td></tr>"
End If
Loop
End If
End If
Rs.close
Set rs=nothing
%>

</table>
<table border= "0" align= "center" >
<tr>
&LT;TD align= "center" valign= "Middle" >
<%call listpages ()%>
</td>
</tr>
</table>
</body>
<%
Sub Listpages ()
If n <= 1 then Exit Sub
%>
<p><span class=smallfont>>>
<%if currentpage = 1 then%>
<font color=darkgray face= "Arial" >top previous</font>
<%else%>
<font color=black face= "Arial" ><a href= "<%=request". ServerVariables ("Script_name")%>?page=1 ">Top</font></a>
<a href= "<%=request. ServerVariables ("Script_name")%>?page=<%=currentpage-1%> ">
<font color=black face= "Arial" >Previous</a></font>
<%end if%>
<%if currentpage = n then%>
<font color=darkgray face= "Arial" >next bottom</font>
<%else%>
<font color=black face= "Arial" ><a href= "<%=request". ServerVariables ("Script_name")%>?page=<%=currentpage+1%> ">Next</a>
<a href= "<%=request. ServerVariables ("Script_name")%>?page=<%=n%> ">Bottom</a></font>
<%end if%>
<font color=black face= "Arial" >
Page:<%=currentpage%>/<%=n%>pages <%=msg_per_page%>notes/page Total:<%=totalrec%>notes </font></span></p>
<%end sub%>


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.