怎么用ASP实现分页(一)

发表于:2007-06-30来源:作者:点击数: 标签:
%@ Language= VB Script % HTML HEAD /HEAD BODY % dim currentpage ‘’定义当前页 dim filename ‘’文件名 Const MaxPerPage=20 ‘’每页显示的记录个数 dim totalnumber ‘’记录总数 filename=showpages.asp totalnumber=200 ‘’设置记录总数为200 if n
<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>

<%
dim currentpage ‘’定义当前页
dim filename ‘’文件名
Const MaxPerPage=20 ‘’每页显示的记录个数
dim totalnumber ‘’记录总数
filename="showpages.asp"
totalnumber=200 ‘’设置记录总数为200

if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
showpages totalnumber,MaxPerPage,filename
%>
</BODY>
</HTML>
<%‘’定义分页的函数,以totalnumber,maxperpage,filename作为函数的入口。
function showpages(totalnumber,maxperpage,filename)
dim n
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
response.write "<form method=Post action="&filename&">"
response.write "<p align=‘’center‘’>记录分页&nbsp;"
if CurrentPage<2 then
response.write "<font color=‘’999966‘’>首页 上一页</font>&nbsp;"
else
response.write "<a href="&filename&"?page=1>首页</a>&nbsp;"
response.write "<a href="&filename&"?page="&CurrentPage-1&">上一页</a>&nbsp;"
end if
if n-currentpage<1 then
response.write "<font color=‘’999966‘’>下一页 尾页</font>"
else
response.write "<a href="&filename&"?page="&(CurrentPage+1)
response.write ">下一页</a> <a href="&filename&"?page="&n&">尾页</a>"
end if
response.write "&nbsp;页次:<strong><font color=red>"&CurrentPage&"</font>/"&n&"</strong>页 &nbsp;"
response.write " 转到:<input type=‘’text‘’ name=‘’page‘’ size=4 maxlength=10 class=smallInput

value="&currentpage&">"
response.write "<input class=buttonface type=‘’submit‘’ value=‘’ Goto ‘’ name=‘’cndok‘’></span></p></form>"

end function
%>

原文转自:http://www.ltesting.net