Master ASP Paging Technology-application skills

Source: Internet
Author: User
Tags prev

Recently looked at some forums above on the paging of the ASP program still has a lot of attention, but there is only code, there is no detailed explanation, for beginners, this is always not really mastered, this time I will be detailed for paging technology, so that everyone can understand the ASP paging, OK, Come to a thorough understanding of the paging process!

First, take a look at the demo!


Look at the function
: The paging program first read the number of preset records per page, this is 5, others will be displayed on the next page, and prompt for the current number of pages, total pages, total records, and when the first page is displayed, the "Home" and "prev" links fail, and when the number of pages displayed is the last page, "Next", "last Page" "Link failed.

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

First, the field Record_info in the database exists in the info table (there is a database in the instance download), first linking the database and opening a recordset, the following code:

<%
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 not clear, I believe that the beginning of the city, the specific explanation can see "hands-on teach you to use ASP to do the message this" tutorial,

Then this is the more important part of the page, with three lines:

<%
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:

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

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

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

Seventh sentence:
Binding the Record_info field that is fetched from the database is called the record loop within the field.

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 the total number of pages with <%=rs.pagecount%>, and read out the total records with <%=rs.recordcount%>. For example: "Current <%=curpage%> page, Total <%=rs.pagecount%> page, 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.

<%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 of the current page is the first page when discriminant, if the current for the first page (that is, home), then display the first two words, no link, otherwise provide direct jump to the homepage of the link.
Previous page:
When you are currently on the first page, the link fails, and in turn, links to the previous page in front, where you use: <%=curpage-1%&gt, that is, by subtracting 1 from the current number of pages and getting the previous page.
Next page:
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, which indicates that this is the next, the link will be invalidated, otherwise linked to the next page.
Last:
As with the function on the next page, the link is invalidated when the last page is found, otherwise the current page is specified 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.