PageSize property of Rs

Source: Internet
Author: User
Tags query rowcount
After understanding the attributes and methods of the Recordset objects, let's consider how they can be used to achieve the purpose of our paging. First, we can set a value for the PageSize property to specify the number of rows that make up a page from the group of records, and then determine the total number of records by the RecordCount property, and then divide the total number of records by PageSize to get the total number of pages displayed. ; Finally, access to the specified page can be completed through the AbsolutePage property. As if it's not complicated, let's take a look at how the program should be implemented.

The automatic numbering of the child; s we build such a simple BBS application, its database has the following five fields: "ID", each post Ubject ", the theme of each post," name ", add the user's name," email ", the user's e-mail address;" Postdate "and add a post to the time." The DSN for the database is "BBS". We'll put all the steps for displaying the post pagination in a process called "showlist ()" for easy invocation. The procedure is as follows:
'----BBS Display posts paging----
<% Sub showlist ()%>
<%
Pgsz=20 ' Set switch, specify the number of posts displayed on each page, default to 20 posts a page
Set Conn = Server.CreateObject ("ADODB. Connection ")
Set RS = Server.CreateObject ("ADODB.") RecordSet ")
sql = "SELECT * from Message ORDER by ID DESC"
' Query all posts and follow the ID of the post in reverse order
Conn.Open "BBS"
Rs.Open sql,conn,1,1
If RS. Recordcount=0 Then
Response.Write "<P><center> Sorry, there is no relevant information in the database!" </center></P> "
Else
Rs. PageSize = Cint (PGSZ) ' Sets the value of the PageSize property
Total=int (RS.RECORDCOUNT/PGSZ *-1) *-1 ' calculates the total number of pages that can be displayed
Pageno=request ("PageNo")
If pageno= "" Then
PageNo = 1
Else
Pageno=pageno+1
Pageno=pageno-1
End If
Scrollaction = Request ("Scrollaction")
If scrollaction = "Previous page" Then
Pageno=pageno-1
End If
If scrollaction = "Next Page" Then
Pageno=pageno+1
End If
If PageNo <1 Then
PageNo = 1
End If
N=1
Rs. AbsolutePage = PageNo
Response.Write "<CENTER>"
Position=rs. Pagesize*pageno
Pagebegin=position-rs.pagesize+1
If position <rs. RecordCount Then
Pagend=position
Else
Pagend= RS. RecordCount
End If
Response.Write "<p><font color= ' Navy ' ><B> database query results:</b>"
Response.Write "(total) &rs. RecordCount & "The information that meets the condition, displays" &pagebegin& "-" &pagend& ") </font></p>"
Response.Write "<table width=600 border=1 cellpadding=4 cellspacing=0 bgcolor= #FFFFFF >"
Response.Write "<tr bgcolor= #5FB5E2 ><font size=2><td><b> Theme </B></TD><TD> <B> user </B></TD><TD><B>Email</B></TD><TD><B> Release date </B> &LT;/TD&GT;&LT;/FONT&GT;&LT;TR bgcolor= #FFFFFF > "
Do While not (RS are nothing)
RowCount = RS. PageSize
Do but not RS. EOF and RowCount > 0
If N=1 Then
Response.Write "<tr bgcolor= #FFFFFF >"
ELSE
Response.Write "<tr bgcolor= #EEEEEE >"
End If
N=1-n%>
<td><span style= "font-size:9pt" ><a href= ' view.asp?key=<% =rs ("ID")%> ' ><% =RS ("subject") %></a></span></td>
<td><span style= "font-size:9pt" ><% =rs ("name")%></a></span></td>
<td><span style= "font-size:9pt" ><a href= "mailto:<% =rs (" email ")%>" ><% =RS ("email")%> </a></span> </TD>
<td><span style= "font-size:9pt" ><% =rs ("postdate")%></span> </td>
</TR>
<%
RowCount = RowCount-1
Rs. MoveNext
Loop
Set rs = rs. NextRecordset
Loop
Conn.close
Set rs = Nothing
Set Conn = Nothing
%>
</TABLE>
<form method=get action= "list.asp" >
<input type= "HIDDEN" name= "PageNo" value= "<% =pageno%>" >
<%
If PageNo > 1 Then
Response.Write "<input type=submit name= ' scrollaction ' value= ' prev ' >"
End If
If rowcount = 0 and PageNo <>total then
Response.Write "<input type=submit name= ' scrollaction ' value= ' next page ' > '
End If
Response.Write "</FORM>"
End If
%>
<% 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.