Introduction to ASP Programming (20): The paging program for ADO components
Source: Internet
Author: User
It should be said, learned how to insert records, how to display records, then the simple complete article system, news system and message system is not a problem. Then the following question is: As the content of the information is increased, it is not rational to display all the information alone through a page. So, the solution is to adopt paging technology.
1,rs. RecordCount
Obviously, RecordCount is used to show how many records there are in a database table, or how many rows there are in a table. Often used in the pagination is a total of n articles, such as total information display.
2,rs. PageSize
Rs. PageSize is also the size of a page, which means that an ASP page can display the number of records. Values are defined by themselves, such as every page that is often seen displaying n articles.
3,rs. AbsolutePage and Rs.pagecount
when it comes to pagination, you must not mention Rs. AbsolutePage. The main function of the AbsolutePage property of a recordset is to decide what page is currently displayed. Its value is based on the designation of Rs. PageSize, then the Rs.pagecount information value is the Rs.recordcount and rs.pagesize divisible result. For example: General Information records Rs. RecordCount total 20, each page shows the number of Rs. PageSize set to 5, then the number of pages Rs.pagecount is 20/5=4 page times, and Rs. AbsolutePage is only the 1th page, page 2nd ... 4th page.
now, get a specific procedure to debug. Continue to modify the showit.asp as follows:
<!--#include file= "conn.asp"-->
<%
Set rs = Server.CreateObject ("ADODB.") Recordset ")
sql = "SELECT * from Cnarticle ORDER BY cn_id Desc"
Rs. Open sql,conn,1,1
%>
<%
page=request.querystring ("page") ' page value is an accepted value
Rs. PageSize = 2 ' shows the number of records per page
Rs. AbsolutePage = Page ' Displays the number of pages that the current page equals to receive
%>
<%
for i = 1 to Rs. PageSize ' uses the For Next loop to read the record of the current page sequentially
if Rs. EOF then
Exit for
End If
Response.Write ("<br> article content is:" & RS ("Cn_content"))
Rs. MoveNext
next%>
<%
Rs.close
Set rs = Nothing
Conn.close
Set conn=nothing
%>
here, you debug the premise is that the database records relative to more than 4, so that the test effect is obvious, and the test method is to showit.asp after the addition of the page=1 or page=2, such as Debugging Observation Web page display effect.
in fact, in the final analysis, the display of database content is
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.