ASP Ajax paging tutorial 1

Source: Internet
Author: User

Why do I need to write ASP paging tutorials to mention Ajax? Because we need to practice more about the structural importance of programming.
In addition, many friends feel very advanced about paging, so they have never dared to touch him, either by using components written by others or by modifying others' things. in particular. net. net is a very good platform. however, because of his severe control, the new user cannot access the idea of programming and cannot find the feeling of programming at all, as if building blocks. sometimes you need to practice something at the bottom, so that your technical skills can be improved. I don't want to use it. net assembler.
Okay. The following is an example of ASP Paging Source code For everyone, I have made a detailed comment, which is generally understandable.
Because this is Tutorial 1, we started from the simplest point. I used absolutepage directly to define the current page, so we didn't use a complicated cursor method such as movefirst, in addition, pagination is also used in the drop-down box. In the next tutorial, I will write an advanced paging method, which will show the method of moving forward ten pages and moving back ten pages. Only the method of displaying the current ten-page group will be shown.
ASP is outdated, but because it can be written in JS, I feel that when I want to use ASP for a project demo. net or Java is more convenient, because it does not need to install a large environment. simply configure it. if large-scale project development is really required, I will certainly use it. net or Java, because this will involve efficiency issues. CopyCode The Code is as follows: <% @ Language = "JavaScript" codePage = "936" %>
<%
// Define the database connection statement
VaR connstring = "provider = Microsoft. Jet. oledb.4.0; Data Source ="
+ Server. mappath ("database/vote. mdb ");
// Create an RS Database Query
VaR rs = server. Createobject ("ADODB. recordset ")
// Rs connection method
Rs. activeconnection = connstring
// Rs query statement (query by user submission time in reverse order)
Rs. Source = "select * from users order by usetime DESC"
// Define the database query mode
Rs. cursortype = 3
Rs. cursorlocation = 3
Rs. locktype = 1
// Define the number of data displayed on each page
Rs. pagesize = 10
// Open the database connection
Rs. open ()
// Define the total number of database records, total number of pages, and URL path
VaR counts, pagecos, thisurl
Counts = Rs. recordcount
Pagecos = Rs. pagecount
Thisurl = request. servervariables ("url ")
// If the cursor is in the table, execute
If (! Rs. EOF |! Rs. bof ){
// If the page parameter of the URL is not empty, execute
If (Request ("page"). Count! = 0 ){
// Define the default link string, the first page, the last page, the previous page, and the next page
// The page value of the URL (the specified current page). The current page shows the number of data entries per page.
VaR defaltstr, firstpage, lastpage, prepage, nextpage, pages, nowpage, nowsize
Defaltstr = '<a href = "' + thisurl + '? Page ='
Firstpage = defaltstr + '1 "> homepage </a>'
Lastpage = defaltstr + pagecos + '"> last page </a>'
Pages = request ("page ")
// If it is on the first page
// Homepage. The previous page is not a link
If (pages <= 1 ){
Rs. absolutepage = 1;
Firstpage = 'homepage'
Prepage = 'prepage'
Nextpage = defaltstr + '2 "> next page </a>'
// If it is on the last page
// The last page. The next page is not a link.
} Else if (pages> = pagecos ){
Rs. absolutepage = pagecos;
Prepage = defaltstr + (pagecos-1) + '"> previous page </a>'
Lastpage = 'end page'
Nextpage = 'Next page'
} Else {
Rs. absolutepage = pages
Prepage = defaltstr + (number (pages)-1) + '"> previous page </a>'
Nextpage = defaltstr + (number (pages) + 1) + '"> next page </a>'
}
}
Nowpage = Rs. absolutepage
Nowsize = Rs. pagesize
// If the last page is displayed and the number of data displayed on each page is not the same
// Because the last page cannot be exactly the same as the number of data displayed on each page
// Define an unequal method
If (nowpage> = pagecos & (pagecos * Rs. pagesize) % counts! = 0 ){
Nowsize = counts % Rs. pagesize
}
%>
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "0" class = "userinfo">
<Tr>
<TD align = "center">
<! -- Display the home page and previous page -->
<% = Firstpage %> <% = prepage %>
Jump to the <select onchange = "location. href = '<% = thisurl %>? Page = '+ this. Value ">
<%
// Pagination by cyclic display
For (VAR num = 1; num <= pagecos; num ++ ){
If (nowpage = num ){
%>
<Option value = "<% = num %>" selected = "selected"> <% = num %> </option>
<%
} Else {
%>
<Option value = "<% = num %>"> <% = num %> </option>
<%
}
}
%>
</SELECT> page
<! -- Display next page and last page -->
<% = Nextpage %> <% = lastpage %>
<! -- Display the current page number, total page number, total number of records, and number of data displayed on each page -->
Total <% = nowpage %>/<% = pagecos %> page <% = counts %>/<% = Rs. pagesize %> records
</TD>
</Tr>
<%
// The content is displayed cyclically.
For (VAR I = 1; I <= nowsize; I ++ ){
%>
<Tr>
<TD> <span> User IP address: </span> <% = RS ("usip") %> </TD>
</Tr>
<Tr>
<TD> <span> suggestion: </span> <% = RS ("US1") %> </TD>
</Tr>
<Tr>
<TD> <span> submission time: </span> <% = RS ("usetime") %> </TD>
</Tr>
<%
// Move the database cursor to the next record
Rs. movenext ();
}
%>
</Table>
<%
// If the database cursor is not in the database Column
} Else {
Response. Write ("no user information! ")
}
// Close the database connection
Rs. Close ()
%>
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.