日期:2014-05-17  浏览次数:21121 次

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)
%>
<p align='center'  ><font color='#ffffff' class='unnamed12'><form method = post>
当前第<%=PageNo%>页/总<%=TotalPage%>页&nbsp;&nbsp;
<%If RecordCount = 0 or TotalPage = 1 Then
Response.Write "首页|前页|后页|末页"
Else%>
<a href="<%=fileName%>?PageNo=1">首页|</a>
<%If PageNo - 1 = 0 Then
Response.Write "前页|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前页|</a>
<%End If
If PageNo+1 > TotalPage Then
Response.Write "后页|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后页|</a>
<%End If%>

<a href="<%=fileName%>?PageNo=<%=TotalPage%>">末页</a>
<%End If%>
&nbsp;&nbsp;转到第
<%If TotalPage <> 1 Then%>
  <input type='text' name=PageNo maxlength=10 class='unnamed12' value='<%=PageNo %>'  style='height:19;width:28;background-color: #F5FCFF; color: #000000; border: 1 solid #5DCEFA;'>
<%Else%>
<input type='text' name=PageNo maxlength=10 class='unnamed12' value='<%=PageNo %>'  style='height:19;width:28;background-color: #F5FCFF; color: #000000; border: 1 solid #5DCEFA;' title=输入页码,回车跳转>
<%End If%>页</form></font></p>
<%End Sub%>

?

??? 使用方法:

         <%
            set rs = server.CreateObject("adodb.Recordset")
            rs.open "select * from UserTab order by UserName", conn, 1, 1
          %>
          <!-- #include file="../TurnPage.asp" -->
          <% 
             Dim RowCount
             RowCount = 10
             Call TurnPage(rs, RowCount)
          %>
        <table >
         <% 
              while (not rs.eof and RowCount > 0)
          %>
           <tr > 
         <td <%=rs("UserName") %></td>
         <td ><%=rs("UserPwd") %></td>
         </tr>
         <% 
             RowCount = RowCount - 1
             rs.movenext
            wend
            rs.close()
          %>
        </table>
?