Learning purpose: paging technology, summary
On the last day of today, we will learn the slightly more difficult paging technology in ASP. After all, when we have N records, we cannot display all the records on one page.
<%
exec="select * from test"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
rs.PageSize=3
pagecount=rs.PageCount
page=int(request.QueryString ("page"))
if page<=0 then page=1
if request.QueryString("page")="" then page=1
rs.AbsolutePage=page
%>
rs.pagesize sets the number of records displayed on a page. Pagecount is a variable defined by ourselves. rs.pagecount is the number of records. Page is also a variable defined by ourselves. Our link to the next page can be set to a list. asp?page=<%=page+1%>, the link to the next page can be set to list.asp?page=<%=page-1%>, so that when the link is clicked, the page itself, the page variable, is called Just +1 or -1. Finally, we just let rs.absolutepage (current page) be the page page.
if request.QueryString("page")="" then page=1, the purpose of this sentence is that when we open list.asp, we do not follow the page variable, and it is automatically set to page=1 to prevent errors, and when we if ....then...end if can be omitted when placed on one line. Is it not difficult to paginate?
Here is a special case:
if page=1 and not page=pagecount, there is no previous page at this time, but there is the next page
elseif page=pagecount and not page=1, there is no next page at this time, but there is the previous page
elseif page<1, there is no record at this time
elseif page>pagecount then, there is no record at this time
elseif page=1 and page=pagecount, at this time there is no previous page and no next page
else, at this time there is the previous page and the next page.
Let's look at a piece of code that displays pages 1 to n, and when each number is clicked, the page represented by that number will appear. It is very common.
<%for i=1 to pagecount%>
<a href="list.asp?page=<%=i%>"><%=i%></a><%next%>
for....next is a loop starting from i=1, and the loop increases by 1 until pagecount.
Finally, my example contains the simplest ASP program, but it has all the functions. It is the essence of ASP. Every large ASP program includes it.
add.htm adds a record page
add.asp adds record operation
conn.asp database link
del.asp delete record operation
modify.asp modify record page
modifysave.asp modify record operation
list.asp is the core of this program, and records can be added, modified, and deleted through this page.
The test.mdb database contains two fields: aa and bb: aa is a numeric type that can only accept numbers, and bb is a character type.
Okay, the ten days are over today. I think this tutorial is for everyone to get started. Don’t blame me if you think the writing is shallow. I will try my best to take care of both beginners and experts. Finally, I want to say something, today The examples are the essence of ASP. You must study them carefully. After passing this program, you will find that you already know ASP. Thank you all for your support!