always there for you

善于生活,善于学习,这是我和你的目标.

Ajax学习心得 »

Asp分页代码

 

       过两天就要党校考试了,今天硬是不想做了,本子上记了好多平常记的东西,先打上来一点,以免以后忘了!
       网页里比较常见的就有分页.一般就是列表页里使用, 


         我把这种列表页分为两种,一种有表单的,一种无表单的。无表单的列表页典型的代表就是新闻列表页面,列表区里只是显示数据以便用户打开相关页面浏览,而有表单的我自认为是管理页面比较常见的,一般是选择所有数据删除比较常见。但分页代码里有表单的话,容易产生表单嵌套。所以分页代码里最好不要有表单。

'---------------------------------------------------------------------------------------------
'分页代码    
'--pages为分页页面,里面可以有个传递参数
'--pageno为当前页码
'-----------------------------------------------------------------------------------------
sub LoadPages(pages,pageno,totalpages,totalrecords)
dim prepgno,nextpgno,cs
cs="?"
if instr(pages,"?")>0 then
cs="&"
end if
response.Write "<table width='90%' height='30' align=center>"&_
   "<tr>"&"<td align='center'>"
  if pageno>1 then
  response.Write "<a href='"&pages&cs&"pageno=1'>首页</a>"
  else
  response.Write "首页"
  end if
response.Write "</td>"
prepgno=pageno-1
nextpgno=pageno+1
response.Write "<td align='center'>"
  if prepgno>=1 then
  response.Write "<a href='"&pages&cs&"pageno="&pageno-1&"'>前一页</a>"
  else
  response.Write "前一页"
  end if
response.Write "</td>"
    response.Write "<td align='center'>"
  if nextpgno<=totalpages then
  response.Write "<a href='"&pages&cs&"pageno="&pageno+1&"'>下一页</a>"
  else
  response.Write "下一页"
  end if
response.Write "</td>"
    response.Write "<td align='center'>"
  if pageno<>totalpages then
  response.Write"<a href='"&pages&cs&"pageno="&totalpages&"'>末页</a>"
  else
  response.Write "末页"
  end if
response.Write "</td>"&_
    "<td align='center'>页数:"&pageno&"/"&totalpages&"</td>"&_
   "<td align='center'>共"&totalrecords&"条记录</td>"&_
            "<td align='center'>转到 </td>"&_
   "<td><input name='pageno' type='text' size='2' maxlength='3' value='"&pageno&"'/></td>"&_
   "<td>页</td>"&_
   "<td align=center>"&_
   "<input type=submit value='Goto'"&_
   "/></td>"&_
    "</tr>"&_
"</table>"
end sub

        在使用时记得根据情况加上表单或不加表单。
        在这里我的分页代码里使用的是文本框提交页面,如果用户是提交正常数据的话,那是没问题,如果填写非数字,网页会报错。
        所以要在显示前过滤字符,当非数字时为1,当为数字时,小于1或大于rs.pagesize时都要有相关处理,这里需要注意的是过滤非数字时如果不用正则表达式的话,用not isnumeric()应该同时加上isempty来过滤数据,因为当一开始打开页面,没传来pageno值,pageno为Empty,而isnumeric(Empty)是为true的。

        如果不想这么麻烦,那就修改分页代码,把文本框该为列表框,改为列表框就可以避免了这种问题。

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Copyright www.alwaysthere.com.cn . Some Rights Reserved.

              

Powered By Z-Blog 1.8 Devo Build 80201