最简单的就是使用分页模块了,要翻页只需调用就可以了,免得次次都要写分页代码,麻烦!
下面为翻页模块 TurnPage.asp
----------------------------------------------------------------------------------------------
<%
'+++++++++++++++++++++++++++++++++++++
'◆模块名称: 公共翻页模块
'◆文 件 名: TurnPage.asp
'◆传入参数: Rs_tmp (记录集), PageSize (每页显示的记录条数)
'◆输 出: 记录集翻页显示功能
'+++++++++++++++++++++++++++++++++++++
'
Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 记录集 ; PageSize 每页显示的记录条数;
Dim TotalPage '总页数
Dim PageNo '当前显示的是第几页
Dim RecordCount '总记录条数
Rs_tmp.PageSize = PageSize
RecordCount = Rs_tmp.RecordCount
TotalPage = INT(RecordCount / PageSize * -1)*-1
PageNo =Request.QueryString ("PageNo")
'直接输入页数跳转;
If Request.Form("PageNo")<>"" Then PageNo =Request.Form("PageNo")
'如果没有选择第几页,则默认显示第一页;
If PageNo = "" then PageNo = 1
If RecordCount <> 0 then
Rs_tmp.AbsolutePage = PageNo
End If
'获取当前文件名,使得每次翻页都在当前页面进行;
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
postion = InstrRev(fileName,"/")+1
'取得当前的文件名称,使翻页的链接指向当前文件;
fileName = Mid(fileName,postion)
%><script language="JavaScript">
<!--
<!--
function test(theForm){
var thisone
thisone = <%=TotalPage%>
if (theForm.PageNo.value == "" || isNaN(theForm.PageNo.value) )
{
alert("请输入一个页数");
theForm.PageNo.focus();
return (false);
}
if (theForm.PageNo.value > thisone || theForm.PageNo.value < 1)
{
alert("不存在此页");
theForm.PageNo.focus();
return (false);
}
return true;
}
// -->
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<form onSubmit="return test(this);" name=theForm method=get>
<table width='100%' border=0 class="en12-black" >
<tr >
<td align=left> <span class="smalltitle">总页数</span>:<font color=#ff3333 class="smalltitle"><%=TotalPage%></font>页
| 当前第<font color=#ff3333 class="smalltitle"><%=PageNo%></font>页 [共有信息<span class="smalltitle"> <%=RecordCount%> </span>条]</td>
<td align="right">
<%If RecordCount = 0 or TotalPage = 1 Then
Response.Write " <img src='images/FIRST.jpg' width='21' height='14' border='0' align='absmiddle'><img src='images/PIEVW.jpg' width='17' height='14' border='0' align='absmiddle'><img src='images/next.jpg' width='15' height='14' border='0' align='absmiddle'><img src='images/last.jpg' width='20' height='14' border='0' align='absmiddle'> "
Else%>
<a href="<%=fileName%>?PageNo=1"> <img src="images/FIRST.jpg" width="21" height="14" border="0" align="absmiddle"> </a>
<%If PageNo - 1 = 0 Then
Response.Write " <img src='images/PIEVW.jpg' width='17' height='14' border='0' align='absmiddle'> "
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>"> <img src="images/PIEVW.jpg" width="17" height="14" border="0" align="absmiddle"> </a>
<%End If
If PageNo+1 > TotalPage Then
Response.Write " <img src='images/next.jpg' width='15' height='14' border='0' align='absmiddle'> "
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>"> <img src="images/next.jpg" width="15" height="14" border="0" align="absmiddle"> </a>
<%End If%>
<a href="<%=fileName%>?PageNo=<%=TotalPage%>"> <img src="images/last.jpg" width="20" height="14" border="0" align="absmiddle"></a>
<%End If%></td>
<td width="120" align="right">转到第
<%If TotalPage = 1 Then%>
<input name=PageNo type=text disabled style="background:#d3d3d3" value="1" size=3 readonly>
<%Else%>
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)" size=1>
<option selected>页码</option>
<%dim pagenum
for pagenum=1 to TotalPage
if TotalPage>1 then
%>
<option value="<%=fileName%>?PageNo=<%=pagenum%>"><%=pagenum%></option>
<%
end if
next
%>
</select>
<%End If%>页
</td>
</tr>
</table></form>
<%End Sub%>
---------------------------------------------------------------------------------------------------------
调用翻页模块
<% set rs= server.CreateObject("adodb.recordset")
rs.open "select * from 数据表 order by 字段 ",conn,1,1
if rs.bof and rs.eof then
response.write"暂无数据"
else
'调用翻页模块
Dim RowCount
RowCount = 20 '每页显示的记录条数
Call TurnPage(rs,RowCount)'公共翻页模块结束
do while not rs.eof and RowCount>0
%>
数据内容
......
......
......
<% RowCount = RowCount - 1
rs.movenext
loop
'调用翻页模块,也可不调用,随个人喜欢
Call TurnPage(rs,RowCount)'公共翻页模块结束
end if
rs.close
set rs=nothing %>