网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.使用ASP与JAVASCRIPT配合实现多个.
.用AspJpeg组件,按宽高比例,真正.
.使用ASP建立Http组件.
.页面延迟的两个简单方法.
.改进性能和样式的 25+ ASP 技巧(.
.如何正确处理数据库中的Null.
.虚拟web目录容易泄露ASP源代码 (.
.Request与Request.Form的速度测试.
.服务器获得客户端时间的方法.
.用正则解析图片地址,并利用XMLHT.
.如何用checkbox做多选删除.
.ASP调用SQL SERVER存储程序 .
.如何在网页中存取剪贴板中的内容.
.支持多风格变换的ASP分页类.
.温柔的杀手—跨站ASP Script攻击.
.ASP如何跳出本次进入下一次循环.
.MS IIS虚拟主机ASP源码泄露 (MS,.
.提高ASP页面的执行效率(上).
.ASP中文本文件与数据库文件的数据.
.如何防止ASP木马在服务器上运行.

Asp用于分页的两个函数

发表日期:2005-10-15


(原创 vince6799)
在asp代码中分页是有点麻烦的事情,个人在在代码编写过程中把分页代码写成了两个函数,虽然在功能上不是很完善,但对于一般的应用应该是满足的了。

<%
'分页函数分为两个函数
'CalcPage(totalrec,msg_per_page,currentpage,n,rowcount,PageRs) 分页计算函数
'PageList(ListType,url,querry,Separator,ListLink) 分页列表函数

'分页计算函数
'totalrec 记录集总数
'msg_per_page 每页显示的记录数,在调用CalcPage时需提前对该变量赋值
'currentpage 当前页变量,在调用CalcPage时需提前对该变量赋值
'n 总页数 
'rowcount 设置每一页的数据记录数
'PageRs 记录集对象
sub CalcPage(totalrec,msg_per_page,currentpage,n,rowcount,PageRs)
 n=0 '设置无记录时页数为0
 if currentpage="" then currentpage=0
 'PageRs.EOF and PageRs.bof  无记录
 'Not PageRs.EOF Or Not PageRs.BOF 有记录
 if Not PageRs.EOF Or Not PageRs.BOF then
  totalrec=PageRs.recordcount
  PageRs.pagesize=msg_per_page
  if totalrec mod msg_per_page = 0 then '计算总页数,recordcount:数据的总记录数
   n = totalrec\msg_per_page 'n:总页数
  else
   n = totalrec\msg_per_page+1
  end if
  if not isnumeric(currentpage) or currentpage="" then currentpage=1
  If currentpage <> "" then
   currentpage = cint(currentpage)
  end if
  if currentpage < 1 then
   currentpage = 1
  end if
  if currentpage*msg_per_page > totalrec and not((currentpage-1)*msg_per_page < totalrec) then
   currentPage=1
  end if
  PageRs.absolutepage = currentpage 'absolutepage:设置指针指向某页开头
  rowcount = PageRs.pagesize            'pagesize:设置每一页的数据记录数
 end if
end sub
%>
<%
'分页列表函数
'url 跳转的地址
'querry ?后的参数
'Separator 分隔符
'ListType 分页类型
'类型:0 "第一页 | 前一页 | 下一页 | 最后页"
'类型:1 "1 | 2 | 3 | 4 | ..........| 下一页"
'类型:2 "第一页 | 前十页 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 后十页 | 最后页"
'ListLink 链接使用的样式

sub PageList(ListType,url,querry,Separator,ListLink)
 if Separator="" then Separator="|"
 if ListType="" then ListType="0"
 select case ListType
  case "0"
   response.write"第"&currentpage&"/"&n&"页&nbsp;&nbsp;"
   response.write"共"&totalrec&"条信息&nbsp;&nbsp;"
   if currentpage <= 1 then
   response.write"第一页&nbsp;"&Separator&"&nbsp;"
   response.write"前一页&nbsp;"&Separator&"&nbsp;"
   else
   response.write"<a href="""&url&"?page=1&"&querry&""" class="""&ListLink&""">第一页</a>&nbsp;"&Separator&"&nbsp;"
   response.write"<a href="""&url&"?page="&currentpage-1&"&"&querry&"""  class="""&ListLink&""">前一页</a>&nbsp;"&Separator&"&nbsp;"
   end if
   if currentpage = n then
   response.write"下一页&nbsp;"&Separator&"&nbsp;"
   response.write"最后页&nbsp;"
   else
   response.write"<a href="""&url&"?page="&currentpage+1&"&"&querry&"""  class="""&ListLink&""">下一页</a>&nbsp;"&Separator&"&nbsp;"
   response.write"<a href="""&url&"?page="&n&"&"&querry&""" class="""&ListLink&""">最后页</a>&nbsp;"
   end if
  case "1"
   if currentpage < n then
    response.write"<a href="""&url&"?page="&currentpage+1&"&"&querry&""" class="""&ListLink&""">下一页</a>&nbsp;"   
   else
    response.write"下一页&nbsp;"   
   end if
   for i=1 to n
    if cstr(i)=cstr(currentpage) then
     response.write "<b>"&i&"</b>"&"&nbsp;"&Separator&"&nbsp;"
     else
      response.write"<a href="""&url&"?page="&i&"&"&querry&""" class="""&ListLink&""">"&i&"</a>&nbsp;"&Separator&"&nbsp;" 
    end if
   next
  
  case "2"
   PageMerCout=10 '每次可翻的最大页数
   '取得记录的最大页码段
   if n mod PageMerCout=0 then
    MaxPageFiled=n\PageMerCout
   else
    MaxPageFiled=n\PageMerCout+1
   end if
   '判断当前页所在的页码段
   if currentpage mod PageMerCout =0 then
    CurrPageFiled=currentpage\PageMerCout
   else
    CurrPageFiled=currentpage\PageMerCout+1
   end if
   '取得当前页码段的最大页码和最小页码
   MaxPageNo=CurrPageFiled*PageMerCout
   MinPageNo=(CurrPageFiled-1)*PageMerCout+1
   '输出 “第一页 | 前十页 |”
   if currentpage<=1 then
    response.write"第一页&nbsp;"&Separator&"&nbsp;"
   else
    response.write"<a href="""&url&"?page=1&"&querry&""" class="""&ListLink&""">第一页</a>&nbsp;"&Separator&"&nbsp;"
   end if
   if CurrPageFiled<=1 then
    response.write"前十页&nbsp;"&Separator&"&nbsp;"      
   else
    response.write"<a href="""&url&"?page="&MinPageNo-PageMerCout&"&"&querry&""" class="""&ListLink&""">前十页</a>&nbsp;"&Separator&"&nbsp;"      
   end if
   '输出当前页码段
   for i=MinPageNo to MaxPageNo
    if i<=n then
     if cstr(i)=cstr(currentpage) then
      response.write "<b>"&i&"</b>"&"&nbsp;"&Separator&"&nbsp;"
      else
       response.write"<a href="""&url&"?page="&i&"&"&querry&""">"&i&"</a>&nbsp;"&Separator&"&nbsp;" 
     end if
    end if
   next
   '输出 “后十页 | 最后页”
   if CurrPageFiled>=MaxPageFiled then
    response.write"后十页&nbsp;"&Separator&"&nbsp;"      
   else
    response.write"<a href="""&url&"?page="&MaxPageNo+1&"&"&querry&""" class="""&ListLink&""">后十页</a>&nbsp;"&Separator&"&nbsp;"      
   end if
   if currentpage>=n then
    response.write"最后页&nbsp;" 
   else
    response.write"<a href="""&url&"?page="&n&"&"&querry&""" class="""&ListLink&""">最后页</a>&nbsp;" 
   end if
 end select
end sub
%>

上一篇:ASP访问INTERBASE数据库 人气:9882
下一篇:ASP与Oracle连接时的TNS错误 人气:9052
浏览全部Asp的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐