ASP编程常用的代码(二)-翻页代码
【
信息来源】 发布日期:
5-8 10:30:00 文章分类:财经资讯
<p><%MaxPerPage=8 '定义页面最大的记录数为8<br>
if not isempty(request("page")) then <br>
currentPage=cint(request("page")) 'currentpage我们作为当前页面的变量,获适当前页的数值<br>
else<br>
currentPage=1 '如果为空就设为1<br>
end if<br>
sql="select * from article order by id desc" 'sql语句,查询article表中的所有数据<br>
Set rs= Server.CreateObject("ADODB.Recordset") <br>
rs.open sql,conn,1,1 '执行sql语句<br>
if rs.eof and rs.bof then <br>
response.write "<p align='center'> 还 没 有 任 何 文 章</p>" <br>
else <br>
totalPut=rs.recordcount '把查询到文章总数的值付给totalput变量(设置第壹页)<br>
if currentpage<1 then '如果小于1<br>
currentpage=1 <br>
end if <br>
if (currentpage-1)*MaxPerPage>totalput then '设置最后一页,如果有溢出,计算页值<br>
if (totalPut mod MaxPerPage)=0 then <br>
currentpage= totalPut \ MaxPerPage <br>
else <br>
currentpage= totalPut \ MaxPerPage + 1 <br>
end if <br>
end if<br>
if currentPage=1 then '假如是第壹页<br>
showpage totalput,MaxPerPage,"index.asp" '执行showpage函数,显示分页<br>
showContent '执行showContent函数,显示内容<br>
showpage totalput,MaxPerPage,"index.asp" '执行showpage函数,显示分页<br>
else '假如不是<br>
if (currentPage-1)*MaxPerPage<totalPut then '当前页*页面最大的记录数是否大于实际总记录数<br>
rs.move (currentPage-1)*MaxPerPage '把记录指针移到当前页的开头<br>
dim bookmark <br>
bookmark=rs.bookmark <br>
showpage totalput,MaxPerPage,"index.asp" <br>
showContent <br>
showpage totalput,MaxPerPage,"index.asp" <br>
else <br>
currentPage=1 <br>
showpage totalput,MaxPerPage,"index.asp" <br>
showContent <br>
showpage totalput,MaxPerPage,"index.asp" <br>
end if <br>
end if <br>
rs.close <br>
end if <br>
set rs=nothing <br>
%></p>
<p><%function showpage(totalnumber,maxperpage,filename) <br>
<br>
dim n <br>
if totalnumber mod maxperpage=0 then <br>
n= totalnumber \ maxperpage <br>
else <br>
n= totalnumber \ maxperpage+1 <br>
end if <br>
response.write "<form method=Post action="&filename&"?typeid="&typeid&">" <br>
response.write "<p align='center'>>>分页 " <br>
if CurrentPage<2 then <br>
response.write "<font color='999966'>首页 上一页</font> " <br>
else <br>
response.write "<a href="&filename&"?typeid="&typeid&"&page=1&>首页</a> " <br>
response.write "<a
href="&filename&"?typeid="&typeid&"&page="&CurrentPage-1&">上一页</a> " <br>
end if <br>
if n-currentpage<1 then <br>
response.write "<font color='999966'>下一页 尾页</font>" <br>
else <br>
response.write "<a href="&filename&"?typeid="&typeid&"&page="&(CurrentPage+1)
<br>
response.write ">下一页</a> <a
href="&filename&"?typeid="&typeid&"&page="&n&">尾页</a>" <br>
end if <br>
response.write " 页次:<strong><font
color=red>"&CurrentPage&"</font>/"&n&"</strong>页 " <br>
response.write " 共<b>"&totalnumber&"</b>个flash<b>"&maxperpage&"</b>个软件/页 "
<br>
response.write " 转到:<input type='text' name='page' size=4 maxlength=10
class=smallInput value="¤tpage&">" <br>
response.write "<input class=buttonface type='submit' value=' 确定 '
name='cndok'></span></p></form>" <br>
end function %></p>