ASP Ajax Pagination Tutorial One _ Application Tips

Source: Internet
Author: User
Tags prev touch
Why do I write ASP paging tutorial to mention Ajax, because we need to practice more of the programming process, the importance of the structure.
Plus a lot of friends on the page feel very advanced, so have been afraid to touch him, either use a component that someone else writes, or change something else. NET, I have a deep feeling that if you want to develop a project quickly, I think. NET is a very good platform. But because of his serious control, On the contrary, the novice is not in touch with the idea of programming, can not find the sense of programming, as if the building blocks. Sometimes it is better to practice a little bit at the bottom so that the technical ability of the individual can be improved. I don't want to do it. NET assembly workers only.
Well, the following gives the source code for the ASP page to everyone, have a detailed annotation, generally can see understand.
Because this is a tutorial one, so from the simplest start, I directly use the AbsolutePage to define the current page, so there is no use such as MoveFirst this more complex cursor mode, and pagination is the use of the Drop-down selection box, and so on the next tutorial I write the advanced pagination method, Give forward 10 pages, back 10 pages, show only the current 10-page grouping method.
Although ASP is an obsolete thing, but because he can use JS to write, so I feel like to do a project demo, using ASP is more convenient than. NET or Java, because he does not have to install a large size of the environment. Simply configure it. If you really want to develop large-scale projects, I'm sure I'll still use it. NET or Java, as this will involve efficiency issues.
Copy Code code as follows:

<% @LANGUAGE = "JAVASCRIPT" codepage= "936"%>
<%
Defining a Database Connection statement
var connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data source="
+server.mappath ("Database/vote.mdb");
Establish an RS database query
var rs = Server.CreateObject ("ADODB.") Recordset ")
RS Connection mode
Rs. ActiveConnection = connstring
RS Query Statement (query in reverse order by user submission time)
Rs. Source = "SELECT * from users ' ORDER by Usetime DESC"
Defining a database query pattern
Rs. CursorType = 3
Rs. CursorLocation = 3
Rs. LockType = 1
Define the number of display data per page
Rs. PageSize = 10
Open a database connection
Rs. Open ()
Define total number of database records, total paging, URL path
var Counts,pagecos,thisurl
Counts = Rs. RecordCount
Pagecos = Rs. PageCount
Thisurl = Request.ServerVariables ("URL")
If the cursor is executed in the table
if (!rs. EOF | | !rs. BOF) {
Executes if the URL's page parameter is not empty
if (Request ("page"). Count!= 0) {
Define default link string, first page, last page, prev, next page
The page value of the URL (the current page specified), the current page, the current number of data displayed per page
var defaltstr,firstpage,lastpage,prepage,nextpage,pages,nowpage,nowsize
Defaltstr = ' <a href= ' ' +thisurl+ '? page= '
FirstPage = defaltstr+ ' 1 "> Home </a> '
LastPage = Defaltstr+pagecos+ ' "> Last </a> '
Pages = Request ("page")
If you are in the first page
Home, previous page is not a link
if (pages <= 1) {
Rs. AbsolutePage = 1;
FirstPage = ' Home '
Prepage = ' previous page '
NextPage = defaltstr+ ' 2 "> next page </a> '
If you are in the last page
Last, next page is not a link
}else if (pages >= Pagecos) {
Rs. AbsolutePage = Pagecos;
Prepage = defaltstr+ (pagecos-1) + ' > Prev </a> '
LastPage = ' last '
nextpage = ' next page '
}else{
Rs. AbsolutePage = pages
Prepage = defaltstr+ (number (pages)-1) + ' > Prev </a> '
NextPage = defaltstr+ (number (pages) +1) + ' > next page </a> '
}
}
Nowpage = Rs. AbsolutePage
Nowsize = Rs. PageSize
If you are on the last page and the number of data displayed is not equal to the number of data displayed per page
Because the last page is unlikely to be equal to the number of data displayed per page each time
So you need to define a method that is not equal.
if (nowpage >= pagecos && (pagecos*rs. PageSize)%counts!= 0) {
Nowsize = Counts%rs. PageSize
}
%>
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" class= "userinfo" >
<tr>
&LT;TD align= "center" >
<!--Display Home page, prev-->
<%=firstpage%> <%=prepage%>
Jump to <select onchange= "location.href= ' <%=thisurl%>?page= ' +this.value" >
<%
Pagination relies on looping 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
<!--show Next page, last-->
<%=nextpage%> <%=lastpage%>
<!--Displays the current number of pages, total number of pages, total records,--> per page display data
Total <%=nowPage%>/<%=pagecos%> page <%=counts%>/<%=rs. Pagesize%> Bar Record
</td>
</tr>
<%
Content relies on looping display
for (Var i=1;i<=nowsize;i++) {
%>
<tr>
<td><span> user Ip:</span><%=rs ("Usip")%></td>
</tr>
<tr>
<td><span> Suggestion: </span><%=rs ("US1")%></td>
</tr>
<tr>
<td><span> Submission Time: </span><%=rs ("Usetime")%></td>
</tr>
<%
Database cursor moves down one record
Rs. MoveNext ();
}
%>
</table>
<%
If the database cursor is not in the database column
}else{
Response.Write ("No user information!")
}
To close a 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.