I know that using some attributes of the recordset component for paging display occupies a lot of resources, and the efficiency is not very high, but as I just learned ASP, it is necessary to at least thoroughly understand this low-level method.
First of all, if you want to use the recordset Component Property for paging display, you must set the value of one of the parameter cursortype in the dataset to 1 (keyboard) pointer.
Actually, it is the attribute to be used in the data set.
Pagesize ---------------- number of records on each page when data is displayed by PAGE
Pagecount --------------- total number of data pages displayed on the data page
Absolutepage ------------ data page of the current pointer
The following is my first small-scale system. The Library Management System displays the pages used by all the books in the library. Code :
<! -- # Include file = "Connections/DB. asp" -->
<%
Dim DB
Set DB = server. Createobject ("ADODB. Connection ")
DB. Open dbqstring
Set rs = server. Createobject ("ADODB. recordset ")
Strsql = "select * From books order by classid"
Rs. Open strsql, DB, 1, 1
%>
<Body bgcolor = "# 6699cc">
<Form name = "form1" method = "Post" Action = "">
<Table width = "200" border = "1" align = "center" cellpadding = "1" cellspacing = "0" bordercolor = "#66 CCFF">
<Tr bgcolor = "#333333" type = "codeph" text = "/codeph">
<TD colspan = "10" nowrap> <Div align = "center"> library list (total <% = Rs. recordcount %> records) </div> </TD>
</Tr>
<Tr bgcolor = "#006699" type = "codeph" text = "/codeph">
<TD nowrap> <Div align = "center"> book number </div> </TD>
<TD nowrap> <Div align = "center"> classification </div> </TD>
<TD nowrap> <Div align = "center"> title </div> </TD>
<TD nowrap> <Div align = "center"> author </div> </TD>
<TD nowrap> <Div align = "center"> price </div> </TD>
<TD nowrap> <Div align = "center"> quantity </div> </TD>
<TD nowrap> <Div align = "center"> press </div> </TD>
<TD nowrap> <Div align = "center"> publication date </div> </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
</Tr>
<%
Dim page_size
Dim page_no
Dim page_total
Page_size = 5 '******************** set to display 5 records per page
If request. querystring ("page_no") = "" then
Page_no = 1
Else
Page_no = CINT (request. querystring ("page_no "))
End if
Rs. pagesize = page_size '******************** pay this number for the recordset object attribute
Page_total = Rs. pagecount '****************** get the total number of pages
Rs. absolutepage = page_no' ****************** set the current page to be displayed for the transfer request
Dim I
I = page_size
Do while not Rs. EOF and I> 0
I = I-1
%>
<Tr>
<TD nowrap> <Div align = "center"> <% = RS ("book_no") %> </div> </TD>
<TD nowrap> <Div align = "center"> <% = RS ("sort_no") %> </div> </TD>
<TD nowrap> <Div align = "center"> <% = RS ("book_name") %> </div> </TD>
<TD nowrap> <Div align = "center"> <% = RS ("author") %> </div> </TD>
<TD nowrap> <Div align = "center"> <% = RS ("price") %> </div> </TD>
<TD nowrap> <Div align = "center"> <% = RS ("amount") %> </div> </TD>
<TD nowrap> <Div align = "center"> <% = RS ("publish") %> </div> </TD>
<TD nowrap> <Div align = "center"> <% = RS ("publish_date") %> </div> </TD>
<TD nowrap> <a href = "update_booksinfo.asp? Classid = <% = RS ("classid") %> "> edit </a> </TD>
<TD nowrap> <a href = "delbook. asp? Classid = <% = RS ("classid") %> "> Delete </a> </TD>
</Tr>
<%
Rs. movenext
Loop
%> </Table>
<Center>
<Span>
<%
* Use the following code to find the specific page *** *********************
Response. Write ("<p> select the data page :")
For I = 1 to page_total
If I = page_no then
Response. Write (I & "& nbsp ")
Else
Response. Write ("<a href = 'showbooks. asp? Page_no = "& I &" '> "& I &" </a> & nbsp ")
End if
Next
* You can use the following method to select a number of pages, rather, go to the next page and click ******************
If page_no <page_total then
Response. Write ("<br> <a href = 'showbooks. asp? Page_no = "& page_no + 1 &" '> next page </a> ")
Else
Response. Write ("<br> last page </a> ")
End if
* You can use the following method to select a number of pages, go to the previous page and click ******************
If page_no> 1 then
Response. Write ("<br> <a href = 'showbooks. asp? Page_no = "& page_no-1 &" '> previous page </a> ")
Else
Response. Write ("<br> homepage </a> ")
End if
* You can use the following method to select a number of pages, the last page is displayed ****************
Response. Write ("<br> <a href = 'showbooks. asp? Page_no = "& page_total &" '> last page </a> ")
* You can use the following method to select a number of pages, the last page is displayed ****************
Dim
A = 1
Response. Write ("<br> <a href = 'showbooks. asp? Page_no = "& A &" '> homepage </a> ")
%>
</Span>
</Center>
</Form>
</Body>
Although this is relatively simple, Beginners should also make it completely clear. Otherwise, they will not be able to learn more efficiently and use resources better.