ASP项目中的asp分页 翻页模块函数

来源:asp之家 时间:2010-04-03 21:03:00 

在大型的ASP项目中,很多的页面都涉及到分页、翻页功能。如果每个页面都写一个翻页的程序的话,这样的工作即降低了工作效率,也不利于工程的模块化,不能使代码重用。因此,把翻页这样的功能模块化是很有必要的。

设计方法:
  1、调用该模块时,只需要传递记录集和每页显示的记录的条数;
  2、可以点击链接进行翻页,也可以直接输入页码,回车后翻页;
  3、不要考虑文件名,程序的每次翻页都能在当前页面。
  想清楚了上面3个问题,我们的公共翻页模块就可以动手了。

<%
'+++++++++++++++++++++++++++++++++++++
'◆模块名称: 公共翻页模块
'◆文 件 名: 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) 
%>
<table border=0 width='100%'> 
<tr> 
<td align=left> 总页数:<font color=#ff3333><%=TotalPage%></font>页
当前第<font color=#ff3333><%=PageNo%></font>页</td>
<td align="right"> 
<%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%></td>
<td width=95>转到第
<%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=请输入页号,然后回车>
<%End If%>页
</td>
</tr>
</table>
<%End Sub%>
  当然,大家可以把翻页的链接做成图片按钮,这样的话也面就更加美观了。
  调用方法:
  1、在程序开始或要使用翻页的地方包含翻页模块文件;
  2、定义变量:RowCount,每页显示的记录条数
  3、调用翻页过程:Call TurnPage(记录集,RowCount)
  4、在Do While 循环输出记录集的条件中加上" RowCount > 0 " 条件
  5、在循环结束 "Loop前" 加上: RowCount = RowCount - 1
'-----------------------------------------------------
调用范例:
文件名: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 '获取的记录集
%>
'公共翻页模块开始%>
<!--#include file=../Public/TurnPage.asp-->
<%
Dim RowCount
RowCount = 10 '每页显示的记录条数
Call TurnPage(Rs_News,RowCount) 
'公共翻页模块结束%> 
%>
<table width=100%>
<tr>
<td>新闻编号</td>
<td>新闻标题</td>
<td>发布日期</td>
<tr>
<%
If Not Rs_News.eof
Do while 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
%>

标签:翻页,函数,分页
0
投稿

猜你喜欢

  • 解决TensorFlow训练模型及保存数量限制的问题

    2022-08-06 08:22:27
  • Python处理excel与txt文件详解

    2021-12-13 20:38:20
  • Dreamweaver技巧50问

    2008-10-16 14:00:00
  • 使用python自动追踪你的快递(物流推送邮箱)

    2022-06-14 11:42:04
  • JavaScript实现全选取消效果

    2023-08-27 16:26:42
  • 数字人组件反写[asp组件开发实例4]

    2009-06-09 13:20:00
  • 影响SQL Server性能的关键三个方面

    2009-02-13 16:59:00
  • 深入解析Python中的变量和赋值运算符

    2023-10-13 20:58:53
  • MySQL系列之十 MySQL事务隔离实现并发控制

    2024-01-25 20:57:35
  • python 将字符串中的数字相加求和的实现

    2022-11-03 22:31:08
  • mysql installer community 8.0.16.0安装配置图文教程

    2024-01-14 00:30:55
  • Python数据分析入门之教你怎么搭建环境

    2023-03-15 12:21:11
  • 基于Python的OpenCV骨架化图像并显示(skeletonize)

    2021-04-29 17:56:21
  • golang中使用匿名结构体的方法

    2023-07-10 07:26:56
  • python中列表元素连接方法join用法实例

    2023-01-20 17:49:31
  • Python from import导包ModuleNotFoundError No module named找不到模块问题解决

    2023-07-27 20:06:53
  • Python使用base64模块进行二进制数据编码详解

    2023-08-26 20:13:13
  • [Oracle] 浅谈Lock与Latch

    2024-01-15 18:02:37
  • python数据处理之Pandas类型转换的实现

    2021-04-11 11:17:36
  • ThinkPHP中__initialize()和类的构造函数__construct()用法分析

    2023-07-08 01:26:24
  • asp之家 网络编程 m.aspxhome.com