Thorough understanding of ASP paging technology very detailed analysis _ Application skills

Source: Internet
Author: User
Tags prev
First, look at the effect!

Look at the function: the paging program first reads the number of preset records per page, this is 5, and others will be displayed on the next page, also prompts the current number of pages, total pages, total records, when the first page is displayed, the "Home", "prev" link is invalid, when the number of pages displayed is the last page, the "Next", "last" link is invalid.

Next, let me tell you how to make this paging effect step-by-step in the way of example.

First of all, the field record_info in the database exists in the info table (when learning ASP pagination, you have a certain understanding of the database), first link the database and open a recordset, the following code:

The following are the referenced contents:

<%
Set conn=server.createobject ("Adodb.connection")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &server.mappath ("Data.mdb")
Conn.Open ConnStr
Set rs=server.createobject ("Adodb.recordset")
Sql= "Select * from Info"
Rs.Open sql,conn,1,1
%>


This code is unknown, I believe that the beginning of the city, the specific explanation can see "hands-on teach you to use ASP to do this" tutorial, then this is the more important part of the page, took three lines just:

The following are the referenced contents:

<%
Rs.pagesize=5
Curpage=request.querystring ("Curpage")
Rs.absolutepage=curpage
%>

Second sentence:

Rs.pagesize = 5, what does this mean? It is a built-in property in the Recordset object, its role is to specify the number of records per page, set to 5 o'clock, every 5 records together into a page, for example, there are 21 records in the instance, then, using rs.pagesize pagination, the 21 records will be divided into 5 pages to display.

Third sentence:

This is mainly used for paging function, the URL of the post parameter curpage passed to the curpage variable, this curpage will be the number of pages visitors want to reach. (Run the example and you'll see)

Sentence IV:

Rs.absolutepage, this is also a built-in property, which means that the value of the Curpage variable is specified as the current page.

Now you can let the record loop show:

The following are the referenced contents:

<%
For i= 1 to Rs.pagesize
If Rs.eof Then
Exit For
End If
%>
<%=rs ("Record_info")%><br>
<%
Rs.movenext
Next
%>

The second sentence: Use the For loop to display the number of records specified in the Rs.pagesize property on each page.

Third chapters: This means that when the last page does not reach the specified record, it exits the loop to avoid errors.

The seventh sentence: binding the Record_info field taken from the database, which is called the record loop in this field is displayed.

The nineth sentence: Use the Rs.movenext method to move the RS recordset down one record.

Tenth sentence: For Loop statement.

In addition, we can read the current page with <%=curpage%>, read out the total number of pages with <%=rs.pagecount%>, and read out the total records with <%= rs.recordcount%>. For example: "Current <%=curpage%> page, a total of <%= rs.pagecount%> pages, a total of:<%=rs.recordcount%> records."

In the display of the first page, prev, next page, last function, the use of if...else ... Statement, compare understood.

The following are the referenced contents:

<%if curpage=1 then%>
Home
<%else%>
<a href= "? curpage=1" > Home </a>
<%end if%>

<%if curpage=1 then%>
Previous page
<%else%>
<a href= "?curpage=<%=curpage-1%>" > Prev </a>
<%end if%>

<%if rs.pagecount<curpage+1 then%>
Next page
<%else%>
<a href= "?curpage=<%=curpage+1%>" > next page </a>
<%end if%> <%if rs.pagecount<curpage+1 then%>
Last
<%else%>
<a href= "?curpage=<%=rs.pagecount%>" > Last </a>
<%end if%>

Understand:

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

Previous page: When the first page is present, the link is invalidated, which, in turn, links to the previous page in front, used here: <%=curpage-1%&gt, that is, to use the current number of pages minus 1 to get the previous page.

Next: 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, that means that this is the next, the link will be invalidated, otherwise linked to the next page.

Last: The same as the next page of the function to determine the last page when the link is invalid, otherwise the current page is designated as Rs.pagecount (total pages).

This is the end of the tutorial, after the explanation, we should have a deeper understanding of the ASP's paging technology? There is a problem can be in the blog message and I contact the way.
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.