盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

ASP项目中的公共翻页模块

时间:2024/12/3作者:未知来源:盾怪网教程人气:

[摘要]</a> <%End If%> <a href="<%=fileName%>?PageNo=<%=TotalPage%>"&...
</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
%>



修正:
<%
If Not Rs_News.eof then
Do while Not Rs_News.eof and RowCount>0
%>

而那个公共模块缺<form>,改后:
<%
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 width="258" align=left> 总页数:<font color=#ff3333><%=TotalPage%></font>页 
当前第<font color=#ff3333><%=PageNo%></font>页 总共<%=RecordCount%>条 </td>
<td width="308" align="right"> <div align="center"> 
<%If RecordCount = 0 or TotalPage = 1 Then 
Response.Write "首页

关键词:ASP项目中的公共翻页模块




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版