最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

Asp用于分页的两个函数ASP技巧

日期:10-20    来源:中国设计秀    作者:cnwebshow.com

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

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

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

sub PageList(ListType,url,querry,Separator,ListLink)2Zx中国设计秀
 if Separator="" then Separator="|"2Zx中国设计秀
 if ListType="" then ListType="0"2Zx中国设计秀
 select case ListType2Zx中国设计秀
  case "0"2Zx中国设计秀
   response.write"第"&currentpage&"/"&n&"页&nbsp;&nbsp;" 2Zx中国设计秀
   response.write"共"&totalrec&"条信息&nbsp;&nbsp;"2Zx中国设计秀
   if currentpage <= 1 then2Zx中国设计秀
   response.write"第一页&nbsp;"&Separator&"&nbsp;"2Zx中国设计秀
   response.write"前一页&nbsp;"&Separator&"&nbsp;"2Zx中国设计秀
   else2Zx中国设计秀
   response.write"<a href="""&url&"?page=1&"&querry&""" class="""&ListLink&""">第一页</a>&nbsp;"&Separator&"&nbsp;" 2Zx中国设计秀
   response.write"<a href="""&url&"?page="&currentpage-1&"&"&querry&"""  class="""&ListLink&""">前一页</a>&nbsp;"&Separator&"&nbsp;" 2Zx中国设计秀
   end if2Zx中国设计秀
   if currentpage = n then2Zx中国设计秀
   response.write"下一页&nbsp;"&Separator&"&nbsp;"2Zx中国设计秀
   response.write"最后页&nbsp;"2Zx中国设计秀
   else2Zx中国设计秀
   response.write"<a href="""&url&"?page="&currentpage+1&"&"&querry&"""  class="""&ListLink&""">下一页</a>&nbsp;"&Separator&"&nbsp;"2Zx中国设计秀
   response.write"<a href="""&url&"?page="&n&"&"&querry&""" class="""&ListLink&""">最后页</a>&nbsp;"2Zx中国设计秀
   end if2Zx中国设计秀
  case "1"2Zx中国设计秀
   if currentpage < n then2Zx中国设计秀
    response.write"<a href="""&url&"?page="&currentpage+1&"&"&querry&""" class="""&ListLink&""">下一页</a>&nbsp;"    2Zx中国设计秀
   else2Zx中国设计秀
    response.write"下一页&nbsp;"    2Zx中国设计秀
   end if2Zx中国设计秀
   for i=1 to n2Zx中国设计秀
    if cstr(i)=cstr(currentpage) then2Zx中国设计秀
     response.write "<b>"&i&"</b>"&"&nbsp;"&Separator&"&nbsp;"2Zx中国设计秀
     else2Zx中国设计秀
      response.write"<a href="""&url&"?page="&i&"&"&querry&""" class="""&ListLink&""">"&i&"</a>&nbsp;"&Separator&"&nbsp;"  2Zx中国设计秀
    end if2Zx中国设计秀
   next2Zx中国设计秀
   2Zx中国设计秀
  case "2"2Zx中国设计秀
   PageMerCout=10 '每次可翻的最大页数2Zx中国设计秀
   '取得记录的最大页码段2Zx中国设计秀
   if n mod PageMerCout=0 then2Zx中国设计秀
    MaxPageFiled=nPageMerCout2Zx中国设计秀
   else2Zx中国设计秀
    MaxPageFiled=nPageMerCout+12Zx中国设计秀
   end if2Zx中国设计秀
   '判断当前页所在的页码段2Zx中国设计秀
   if currentpage mod PageMerCout =0 then2Zx中国设计秀
    CurrPageFiled=currentpagePageMerCout2Zx中国设计秀
   else2Zx中国设计秀
    CurrPageFiled=currentpagePageMerCout+12Zx中国设计秀
   end if2Zx中国设计秀
   '取得当前页码段的最大页码和最小页码2Zx中国设计秀
   MaxPageNo=CurrPageFiled*PageMerCout2Zx中国设计秀
   MinPageNo=(CurrPageFiled-1)*PageMerCout+12Zx中国设计秀
   '输出 “第一页 | 前十页 |”2Zx中国设计秀
   if currentpage<=1 then2Zx中国设计秀
    response.write"第一页&nbsp;"&Separator&"&nbsp;" 2Zx中国设计秀
   else2Zx中国设计秀
    response.write"<a href="""&url&"?page=1&"&querry&""" class="""&ListLink&""">第一页</a>&nbsp;"&Separator&"&nbsp;" 2Zx中国设计秀
   end if2Zx中国设计秀
   if CurrPageFiled<=1 then2Zx中国设计秀
    response.write"前十页&nbsp;"&Separator&"&nbsp;"       2Zx中国设计秀
   else2Zx中国设计秀
    response.write"<a href="""&url&"?page="&MinPageNo-PageMerCout&"&"&querry&""" class="""&ListLink&""">前十页</a>&nbsp;"&Separator&"&nbsp;"       2Zx中国设计秀
   end if2Zx中国设计秀
   '输出当前页码段2Zx中国设计秀
   for i=MinPageNo to MaxPageNo2Zx中国设计秀
    if i<=n then2Zx中国设计秀
     if cstr(i)=cstr(currentpage) then2Zx中国设计秀
      response.write "<b>"&i&"</b>"&"&nbsp;"&Separator&"&nbsp;"2Zx中国设计秀
      else2Zx中国设计秀
       response.write"<a href="""&url&"?page="&i&"&"&querry&""">"&i&"</a>&nbsp;"&Separator&"&nbsp;"  2Zx中国设计秀
     end if2Zx中国设计秀
    end if2Zx中国设计秀
   next2Zx中国设计秀
   '输出 “后十页 | 最后页”2Zx中国设计秀
   if CurrPageFiled>=MaxPageFiled then2Zx中国设计秀
    response.write"后十页&nbsp;"&Separator&"&nbsp;"       2Zx中国设计秀
   else2Zx中国设计秀
    response.write"<a href="""&url&"?page="&MaxPageNo+1&"&"&querry&""" class="""&ListLink&""">后十页</a>&nbsp;"&Separator&"&nbsp;"       2Zx中国设计秀
   end if2Zx中国设计秀
   if currentpage>=n then2Zx中国设计秀
    response.write"最后页&nbsp;"  2Zx中国设计秀
   else2Zx中国设计秀
    response.write"<a href="""&url&"?page="&n&"&"&querry&""" class="""&ListLink&""">最后页</a>&nbsp;"  2Zx中国设计秀
   end if2Zx中国设计秀
 end select2Zx中国设计秀
end sub2Zx中国设计秀
%>2Zx中国设计秀

本文引用地址:/bc/article_46545.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明