当前位置: 首页 > 图文教程 > 网络编程 > ASP > 模仿PHP写的ASP分页

ASP
连接数据库查询手册
ASP.net组件编程中的两种事件编写方法
简单快捷实现ASP在线发邮件
ASP能读写注册表
用ASP实现在线压缩与解压缩
Asp编写不再让人讨厌的自动弹出窗口
使用组件封装ASP的数据库操作
删除Access数词库中的空记录
制做行背景颜色交替变换的表格
将数据库中的信息存储至XML文件中
如何用foreach遍历页面上所有的TextBox
asp.net如何生成图片验证码(简单)
WEB表格导出为EXCEL文档的方法
ASP上两个防止SQL注入式攻击Function
xmlHTTP技术资料
提高ASP.NET性能的方法
DataGrid 分页问题
如何固定表格的标题行和标题列
在B/S系统中引入定时器的功能
关于用ASP.Net识别远程主机服务器种类

模仿PHP写的ASP分页


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 36 ::
收藏到网摘: n/a

       <%
  ' 分页程序
  ' total_records 总记录数
  ' everypage_records 每页显示条数
  ' current_page 当前页数
  ' url 要传递的url,这里可以含有要传递的变量,比如 "list.asp?" 或者"list.asp?keyword=key&"
  ' 程序调用比较简单,不过还是比PHP的麻烦,继续努力中
  
  sub show_page(total_records,everypage_records,current_page,url)
  
   if IsNumeric (total_records) then
   total_records=Int(total_records)
   else
   total_records=0
   end if
  
   if IsNumeric (everypage_records) then
   everypage_records=Int(everypage_records)
   if everypage_records<=0 then
   everypage_records=10
   end if
   else
   everypage_records=10
   end if
  
   if IsNumeric (current_page) then
   current_page=Int(current_page)
   else
   current_page=1
   end if
  
   '取总页数,即最后一页
   if total_records mod everypage_records=0 then
   last_page=Int(total_records/everypage_records)
   else
   last_page=Int(total_records/everypage_records)+1
   end if
  
   '判断 current_page 是否符合标准,并附值给page
   if current_page>=last_page then
   page=last_page
   elseif current_page<=1 then
   page=1
   else
   page=current_page
   end if
  
   '上一页
   if page<=0 then
   prepg=0
   else
   prepg=page-1
   end if
   '下一页
   if page=last_page then
   nextpg=0
   else
   nextpg=page+1
   end if
  
   '本页开始记录
   firstcount=prepg*everypage_records
   '本页结束记录
   if nextpg>=1 then
   lastcount=(nextpg-1)*everypage_records
   else
   lastcount=total_records
   end if
   '开始分页导航条代码
   pagenav=""
   pagenav1=""
   pagenav=pagenav&"显示第<b>"&firstcount&"-"&lastcount&"</b>条记录 共<b>"&total_records&"</b> 条记录"
   pagenav1=pagenav1&"显示第<b>"&firstcount&"-"&lastcount&"</b>条记录 共<b>"&total_records&"</b> 条记录"
  
   if last_page>1 then
   '当有前后页时
   pagenav=pagenav&" <a href='"&url&"page=1'>首页</a> "
   pagenav1=pagenav1&" <a href='"&url&"page=1'>首页</a> "
   if prepg>=1 then
   pagenav=pagenav&" <a href='"&url&"page="&prepg&"'>前页</a> "
   pagenav1=pagenav1&" <a href='"&url&"page="&prepg&"'>前页</a> "
   else
   pagenav=pagenav&" 前页 "
   pagenav1=pagenav1&" 前页 "
   end if
   if nextpg>=1 then
   pagenav=pagenav&" <a href='"&url&"page="&nextpg&"'>后页</a> "
   pagenav1=pagenav1&" <a href='"&url&"page="&nextpg&"'>后页</a> "
   else
   pagenav=pagenav&" 后页 "
   pagenav1=pagenav1&" 后页 "
   end if
   pagenav=pagenav&" <a href='"&url&"page="&last_page&"'>尾页</a> "
   pagenav1=pagenav1&" <a href='"&url&"page="&last_page&"'>尾页</a> "
  
   pagenav=pagenav&"到第<input type=text name=text100 id=text100 value="&page&" size=3>页<input type=button name=button100 value=go onclick='window.location="""&url&"page=""+text100.value'>"
   page