I have read some forums recently. There are still many referers about the pagination ASP program, but there is only code in it and there is no detailed explanation. For Beginners, this will always be hard to grasp, I will explain the paging technology in detail this time, so that you can understand ASP paging. Well, let's get a thorough understanding of the paging program!
First, let's take a look at the demo!
View features: The paging program first reads the number of Preset records on each page, which is five. The others will be displayed on the next page, and the current page number, total page number, and total number of records will be displayed, when the displayed page number is the first page, the "Homepage" and "Previous Page" links are invalid. When the displayed page number is the last page, the "next page" and "last page" links are invalid.
Next, we will show you how to implement this paging effect step by step in the form of instances.
First, the record_info field in the database exists in the info table (a database exists in the instance download). First, connect to the database and open a record set. 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 explained in detail. I believe it will be used for beginners. For specific explanations, please refer to the Tutorial "teach you how to use ASP as a message book,
Next, this is an important part of the page. There are three rows:
<%
Rs. pagesize = 5
Curpage = Request. QueryString ("curpage ")
Rs. absolutepage = curpage
%>
Second sentence:
Rs. pagesize = 5. What does this mean? It is a built-in attribute in the Recordset object. It specifies the number of records on each page. When set to 5, every five records are put together into one page, for example, if there are 21 records in the instance, use rs. after pagesize is paginated, the 21 records are displayed on 5 pages.
Third sentence:
This is mainly used for page turning. The URL post parameter curpage is passed to the curpage variable, which will get the number of pages that the browser wants to reach. (Run the instance to understand)
Fourth sentence:
Rs. absolutepage, which is also a built-in attribute, indicates that the value of the curpage variable is specified as the current page.
Now, record loops can be displayed:
<%
For I = 1 to rs. pagesize
If rs. eof then
Exit
End if
%>
<% = Rs ("record_info") %> <br>
<%
Rs. movenext
Next
%>
Second sentence:
The for loop is used to display the number of records specified in the rs. pagesize attribute on each page.
The third, fourth, and fifth sentences:
This means that the loop is exited when the last page does not reach the specified record to avoid errors.
Seventh sentence:
Bind the record_info Field Retrieved from the database, that is, the records in this field are displayed cyclically.
Ninth sentence:
Use the rs. movenext method to move the rs record set down one record.
Sentence 10:
For Loop statement.
You can also use <% = curpage %> to read the current page and use <% = rs. pagecount %> Read the total number of pages, with <% = rs. recordcount %> total number of records read. For example, the current page <% = curpage %> contains a total of <% = rs. pagecount %> pages and a total of <% = rs. recordcount %> records ".
The if... else... statement is used to display the homepage, top page, Bottom page, and end page.
<% If curpage = 1 then %>
Homepage
<% Else %>
<A href = "? Curpage = 1 "> homepage </a>
<% End if %>
<% If curpage = 1 then %>
Previous Page
<% Else %>
<A href = "? Curpage = curpage-1 %> "> previous page </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 page
<% Else %>
<A href = "? Curpage = <% = rs. pagecount %> "> last page </a>
<% End if %>
Understanding:
Home page:
This parameter is used to determine whether the current page is the first page. If the current page is the first page (that is, the homepage), there is no link to the homepage. Otherwise, a link is provided to directly jump to the homepage.
Previous Page:
When the current is the first page, the link becomes invalid, in turn, link to the current Previous Page, here using: <% = curpage-1 %>, is to get the previous page with the current page minus 1.
Next page:
Here we need to use the rs. pagecount attribute for comparison. If the total number of pages is less than the value of the current number plus 1, it indicates that this is the first page, and the link will be invalid; otherwise, it will be linked to the next page.
Last page:
The link is invalid when the last page is determined like the function of the next page. Otherwise, the current page is specified as rs. pagecount (total number of pages ).
This tutorial ends now. After explanation, should you have a deep understanding of ASP paging technology? If you have any questions, contact me by leaving a message on the blog.