免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 916 | 回复: 0
打印 上一主题 下一主题

创建一个ASP通用分页类(二) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-27 11:18 |只看该作者 |倒序浏览

创建一个ASP通用分页类(二)
作者:互联网 文章来源:互联网 点击数:
1021 更新时间:2005-10-13
我们继续接上期
在页面里通过调用ShowPage()的方法显示出来,ShowPage可以在GetRS以后的任意位置调用,也可以调用多次
Public Sub ShowPage()
Dim str_tmp
int_totalRecord=XD_RS.RecordCount
If int_totalRecordint_Totalpage Then
  int_curpage=int_TotalPage
End If
'=====================================================
'显示分页信息,各个模块根据自己要求更改显求位置
'=====================================================
response.write "
str_tmp=ShowFirstPrv '显示首页、前一页
response.write str_tmp  
str_tmp=showNumBtn '数字导航
response.write str_tmp
str_tmp=ShowNextLast  '下一页、末页
response.write str_tmp
str_tmp=ShowPageInfo
response.write str_tmp
response.write ""
end Sub

到这里类的功能才算完整(为了节省版面,我有些方法没有放上去,再下面附上全部完整代码)写一个简单页面测试一下
")
for i=1 to mypage.pagesize
'这里就可以自定义显示方式了
    if not rs.eof then
        response.write rs(0) & ""
        rs.movenext
    else
         exit for
    end if
next
%>

效果还不错,该有的全有了。
分页过程中,还有一个比软麻烦的问题是,在带多个参数的URL中,如保证在页面转向的时候不掉失其它参数。我靠一个GetURL的过程来实现,并在生成导航时调用。
Private Function GetURL()
  Dim strurl,str_url,i,j,search_str,result_url
  search_str="page="
  strurl=Request.ServerVariables("URL")
  Strurl=split(strurl,"/")
  i=UBound(strurl,1)
  str_url=strurl(i)'得到当前页文件名
  str_params=Request.ServerVariables("QUERY_STRING")
  If str_params="" Then
  result_url=str_url & "?page="
  Else
  If InstrRev(str_params,search_str)=0 Then
result_url=str_url & "?" & str_params &"&page="
  Else
j=InstrRev(str_params,search_str)-2
If j=-1 Then
  result_url=str_url & "?page="
Else
  str_params=Left(str_params,j)
  result_url=str_url & "?" & str_params &"&page="
End If
  End If
  End If
  GetURL=result_url
End Function
通过GetURL的处理,可以自动的获取当前面的文件名,和所有带的参数,实现了页面转换页不丢失参数。
三、后记
通过这个分页类,解决了每次分页时需要重复写的分页部分代码,方便了编程,也使的提高了主要代码的可读性。也希望能给大家在编程过程中带来一点方便,由于本人水平有限,程序和文章中难免有错,还望大家批评指正。
全部代码下载


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/17578/showart_105463.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP