Page Flipping | Projects in large ASP projects, many pages are related to the paging function. If each page writes a flip-through program, this kind of work reduces the working efficiency, also is not advantageous to the project modularization, cannot make the code reuse. Therefore, it is necessary to modularize the function of paging.
Design method:
1, call the module, only need to pass the recordset and the number of records displayed on each page;
2, you can click on the link to page, you can also directly enter the page number, return to the page;
3, do not consider the filename, the program every page can be in the current pages.
To figure out the top 3 questions, our public paging module is ready to go.
<%
'+++++++++++++++++++++++++++++++++++++
' Module name: Public paging module
' FileName: turnpage.asp
' Incoming parameters: Rs_tmp (Recordset), PageSize (number of record bars per page)
' Output: Recordset paging display feature
'+++++++++++++++++++++++++++++++++++++
'
Sub turnpage (ByRef rs_tmp,pagesize) ' rs_tmp recordset PageSize the number of record bars displayed per page;
Dim totalpage ' Total pages
Dim PageNo ' is currently showing the first few pages
Dim RecordCount ' Total record bar count
Rs_tmp. PageSize = PageSize
RecordCount = rs_tmp. RecordCount
Totalpage = INT (recordcount/pagesize *-1) *-1
PageNo = Request.QueryString ("PageNo")
' Direct input page jump;
If Request.Form ("PageNo") <> "" Then PageNo = Request.Form ("PageNo")
' If the page is not selected, the first page is displayed by default;
If pageno = "" Then PageNo = 1
If RecordCount <> 0 Then
Rs_tmp. AbsolutePage = PageNo
End If
' Get the current file name so that each page is on the current screen;
Dim filename,postion
FileName = Request.ServerVariables ("Script_name")
postion = InStrRev (FileName, "/") +1
' Get the current file name so that the page-flipping link points to the current file;
FileName = Mid (filename,postion)
%>
<table border=0 width= ' 100% ' >
<tr>
<TD align=left> Total Pages: <font color= #ff3333 ><%=TotalPage%></font> page
Current page <font color= #ff3333 ><%=PageNo%></font> page </td>
<TD align= "Right" >
<%if RecordCount = 0 or totalpage = 1 Then
Response.Write "Home | front page | next page | last"
Else%>
<a href= "<%=FILENAME%>? Pageno=1 "> Home |</a>
<%if PageNo-1 = 0 Then
Response.Write "Previous Page |"
Else%>
<a href= "<%=FILENAME%>? Pageno=<%=pageno-1%> "> front page |</a>
<%end If
If pageno+1 > Totalpage Then
Response.Write "Back Page |"
Else%>
<a href= "<%=FILENAME%>? Pageno=<%=pageno+1%> "> Back page |</a>
<%end if%>
<a href= "<%=FILENAME%>? Pageno=<%=totalpage%> "> Last </a>
<%end if%></td>
<TD width=95> go to page
<%if totalpage = 1 then%>
<input type=text name=pageno size=3 readonly disabled style= "background: #d3d3d3" >
<%Else%>
<input type=text Name=pageno size=3 value= "" title= Please enter the page number, then return >
<%end if%> Page
</td>
</tr>
</table>
<%end sub%>
Of course, you can turn the link into the page to make the picture button, so that the surface will be more beautiful.
Call Method:
1. Include the paging module file at the beginning of the program or where the page is to be used;
2, define variables: RowCount, the number of records displayed per page
3, call the page process: called Turnpage (Recordset, ROWCOUNT)
4. Add the "RowCount > 0" condition to the condition of the Do While loop output recordset
5, at the end of the loop "loop before" plus: RowCount = RowCount-1
'-----------------------------------------------------
Invocation Example:
FileName: news.asp
<%
Dim Conn,rs_news
Set Conn = server. CreateObject ("ADODB.") CONNECTION ")
Conn.Open "CPM", "CPM", "CPM"
Dim SQL
SQL = "SELECT * FROM News"
Set rs_news = Server.CreateObject ("ADODB. RECORDSET ")
Rs_news.open sql,conn,1,3 ' captured recordset
' Public paging module starts%>
<!--#include file=. /public/turnpage.asp-->
<%
Dim ROWCOUNT
RowCount = 10 ' Number of record bars displayed per page
Call Turnpage (Rs_news,rowcount)
' Public paging module end%>
<table width=100%>
<tr>
<td> News Number </td>
<td> News title </td>
<td> Release date </td>
<tr>
<%
If not rs_news.eof
Do, not rs_news.eof and rowcount>0
%>
<tr>
<td><%=rs_news ("ID")%></td>
<td><%=rs_news ("Name")%></td>
<td><%=rs_news ("Date")%></td>
<tr>
<%
RowCount = RowCount-1
Rs_news.movenext
Loop
End If
%>