Using ASP to realize paging browsing of table (top)

Source: Internet
Author: User
Tags count implement
pagination | We all know that ASP has a powerful database operation capability, which is inseparable from her convenient invocation of ActiveX objects. Let me introduce an ASP method of using ADO object to realize paging display of database records. The following code is passed under the win98+pws+msaccess environment.

Here I mainly through the ADO object set of Recordset object to implement a variety of database operations. First, several recordset properties for paging display are introduced.

PageSize: The number of records displayed per page.

PageCount: According to the user set up the pagesize and the total number of records in the table, the system automatically calculates total pages.

RecordCount: The total number of records in the table.

AbsolutePage: Represents the current page number. If you set the AbsolutePage property to 3, the current record moves to page 3rd 1th (that is, 31st).

After seeing the recordset with these attributes, I believe we all feel that it is easy to do a paging display program. Here is a thought, all the code to implement this function is placed in the display.asp, according to the Order of execution is: Open the database and table, read the user requirements of the display, set up a good pagesize and AbsolutePage, output the content to the browser, set a good navigation bar. Here's the code:


<% '---------------------------Open database and table
Set Conn=server.createobject ("ADODB. Connection ")
Filepath=server.mappath ("Abc.mdb") '-------assume that the database file is "Abc.mdb"
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & filepath
Set Rs=server.createobject ("ADODB. Recordset ")
Rs.Open "main", conn,3,2 '-------assume the name of the table is "main"
%>
<% '---------------------------read the display of user requirements (passed by parameter)
Line=cint (Request ("line"))
Page=cint (Request ("page")
%>
<% '---------------------------Set the display mode according to the user's requirement.
Rs. Pagesize=line
Rs. Absolutepage=page
%>
<% '---------------------------Display content%>
<table width= "100%" border= "1"
<tr>
<%for i=0 to Rs. fields.count-1%>
<td> <%=rs. Fields (i). name%> </td>
<%next%>
</tr> <% '-------The above section shows the header, which is the field name%>
<%for I=1 to Rs. pagesize%>
<tr>
<%for j=0 to Rs. fields.count-1%>
<td> <%=rs. Fields (j). value%> </td>
<%next%>
</tr>
<%rs.movenext%>
<%if rs.eof Then Exit for%>
The <%next%> <% '-------shows the contents of the table in the above section%>
</table>

<% '---------------------------navigation bar%>



<%if page <> 1 then%>
> first page
<%else%> first page <%end if%>

</td>
<td>
<%if page>1 then%>
<a Href=display.asp?page= <%=page-1%> &line= <%=line%> > previous page </a>
<%else%> Previous page <%end if%>
</td>
<td>
<%if page<rs. PageCount then%>
<a Href=display.asp?page= <%=page+1%> &line= <%=line%> > next page
<%else%> Next page <%end if%>
</td>
<td>
<%if page <> Rs. PageCount then%>
<a Href=display.asp?page=<%=rs. Pagecount%>&line= <%=line%> > last page </a>
<%else%> last page <%end if%>
</td> <% '-------all of the above four items need to be judged: if you do not provide the first page and previous page links on the first page
'-------If you do not provide a link to the last page and the next page on the last page%>
<td>
<form method= "POST" action= "display.asp?line= <%=line%>" >
Please enter page number: <input type= "text" name= "page" size= "3" value= "<%=page%>" >
</form>
</td>
<td>
<form method= "POST" action= "display.asp?page= <%=page%>" >
Please set each page <input type= "text" name= "line" size= "3" value= "<%=line%>" >
</form>
</td> <% '-------because there is only one form field in all two forms, no Send button is provided, just hit the carriage return line%>
<td>
Page <%=page%>/Total <%=rs. pagecount%> page
</td>

This is just a basic program, no optimization, there are some bugs, let's make it more "perfect" some of the following.



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.