CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  ASP

关于分页

楼主chfeijj(阿土)2003-08-03 22:49:22 在 Web 开发 / ASP 提问

有人可以告诉我一些关于  
  分页的技巧吗!  
  我在这个地方难住了!  
  用上去了可是有问题!  
  问题点数:0、回复次数:3Top

1 楼zorou_fatal(The world and system is even)回复于 2003-08-03 22:53:20 得分 0

建立一个rst对象。  
  然后用1,1方式打开  
  设置好rst对象的pagesize属性(每页显示的记录条数)  
  设置好rst对象的absolutepage属性(当前是第几页)  
  显示。  
  注意这里的sql语句里的查询条件和absolutepage   的值的传递方式。Top

2 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2003-12-14 13:22:03 得分 0

 
    ASP学习史上最强的数据分页方法    
     
    我观前辈的帖子,皆由于数据库的SQL大不一致,且SQL   SERVER,ACCESS等菜鸟级数据库没有如rowid,_n_,obs等之类的辅助列,空有BETWEEN运算符而无用武之地,  
  又无如except之类的数据集运算符,真是令无数英雄尽折腰  
   
     
   
    偶详观各数据库SQL,得出是数据库就有取前面N条记录的SQL语法,如什么select   top   n*****之类的语法,而数据分页的关键问题是取后N条记录的语法偶深思良久,最后小悟,故出此言,还忘前辈们多多指点  
      
    取记录集后N条记录的大法:  
      
    假设:  
      
       1.有一sql语句将产生1000条记录   (select   唯一ID,其他字段   from   表集   where   条件   order   by   排序)  
       2.每页显示20条记录  
       3.当前显示第5页  
      
    实现如下:  
       select   *   from    
       (  
       select   *   from   (select   top   20*4   唯一ID,其他字段   from   表集   where   条件   order   by   排序)   as   a  
       union   all  
       select   *   from   (select   top   20*5   唯一ID,其他字段   from   表集   where   条件   order   by   排序)   as   b    
       )    
       a    
       group   by   唯一ID,其他字段   having   count(唯一ID)=1   order   by   排序  
        
    运行此SQL,至此取记录集后N条记录大法就些完毕  
      
    详细说明:  
      
    此SQL语句的关键应用技巧在于union   all和分组上的条件过滤语句  
      
    大家可以根据此技巧完全可以做出一个通用的分页方法,如直接由用户传入sqlstr(sql语句),NumPerPage(每页显示数),currpage(当前页),自己在再函数内组织成通成的SQL分页语句  
      
    备注:  
      
    当前页为1的话就不需要运行该SQL了,直接TOP一下就OK了  
    由于没有环境,该SQL性能无法测试,但相信不会低效  
    运行平台在access,sqlserver上都可运行,其它数据库平台只需改top关键字应该就可以就地运行了  
   
   
   
   
   
  Top

3 楼wsqsoft(knbaba)回复于 2003-12-14 13:30:17 得分 0

<!--#include   file   =include/conn.asp-->  
  <!--   #include   file="include/const.asp"   -->  
  <head>  
  <title>欢迎光临扬子江(连锁)饭店--管理页面</title>  
  <link   rel="stylesheet"   href="include/forum_admin.css"   type="text/css">  
  <meta   NAME=GENERATOR   Content="Microsoft   FrontPage   4.0"   CHARSET=GB2312>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312"></head>  
  <BODY   leftmargin="0"   topmargin="0"   marginwidth="0"   marginheight="0">  
  <%  
          select   case   request("action")  
          case   "modify"  
  call   modify()  
          case   "savemodify"  
  call   savemodify()  
  case   "del"  
  call   delete()  
  case   "CancelHot"  
  call   CancelHot()  
  case   else  
  call   main()  
  end   select  
   
  sub   delete()  
      sql="delete   from   starcn   where   ID="   &   request("ID")  
      conn.execute(sql)  
      response.redirect   Request.ServerVariables("HTTP_REFERER")  
  end   sub  
   
   
  sub   main()  
  %>  
  <table   width="95%"   border="0"     align=center   cellpadding="3"   cellspacing="1">  
  <form   method="POST"   action="?action=Search">  
  <tr>    
              <td   height=25   align=left   width="715"><a   href="admin.asp">〖返回管理主页〗</a></td>  
  </tr>  
  <tr>    
              <td   height=25   align=left   width="715"><B>说明</B>:用户留言管理,点击编辑、删除进行相应操作。</td>  
  </tr>  
  </form>    
  </table>  
      <table   width="95%"   border="0"     align=center   cellpadding="3"   cellspacing="1"   bgcolor="FCF6DF"   class="tableBorder">  
  <form   method="POST"   name="his"   action="admin_news_list.asp">  
  <tr   bgcolor="F7E8AF">  
  <th   id=tabletitlelink>主题</th>  
  <th   id=tabletitlelink>作者</th>  
  <th   id=tabletitlelink>电子邮箱</th>  
  <th   id=tabletitlelink>留言日期</th>  
  <th   id=tabletitlelink></th>  
  <th   id=tabletitlelink></th>  
  </tr>  
  <%  
      dim   currentpage,page_count,Pcount  
      dim   totalrec,endpage  
       
      currentPage=request("page")      
  if   currentpage=""   or   not   isInteger(currentpage)   then  
  currentpage=1  
  else  
  currentpage=clng(currentpage)  
  if   err   then  
  currentpage=1  
  err.clear  
  end   if  
  end   if  
   
      set   rs=Server.CreateObject("ADODB.recordset")  
      sql="select   *   from   [starcn]     order   by   ID   DESC"  
      rs.open   sql,conn,1,1  
   
  if   rs.eof   and   rs.bof   then  
  %>  
  <tr><td   colspan=6   class=forumrow>  还没有任何用户数据。</font></td></tr>  
  <%  
  else  
          rs.PageSize   =Forum_Setting(11)  
          totalrec=rs.recordcount  
          rs.AbsolutePage=currentpage  
           
  while   (not   rs.eof)   and   (not   page_count   =   rs.PageSize)  
  %>  
          <tr>    
              <td   class="forumrow"><%=myTrim(rs("mess_title"),20)%></td>      
              <td   class="forumrow"><%=rs("mess_auther")%></td>      
              <td   class="forumrow"><%=rs("mess_email")%></td>      
              <td   class="forumrow"   align=center><%=rs("mess_date")%></td>      
              <td   class="forumrow"   align=center><a   href="?action=modify&ID=<%=rs("ID")%>">查看</a></td>      
              <td   class="forumrow"   align=center><a   href="?action=del&ID=<%=rs("ID")%>">删除</a></td>      
          </tr>  
  <%  
      page_count   =   page_count   +   1  
                      rs.movenext  
                  wend  
   
          Pcount=rs.PageCount  
  %>  
          <tr   bgcolor=<%=Forum_body(3)%>>    
              <td   class=Forumrow   height="7"   colspan="6">  
  <table   border=0   cellpadding=0   cellspacing=3   width="<%=Forum_body(12)%>"   align=center>  
  <tr><td   valign=middle   nowrap>  
  <font   color=<%=Forum_body(13)%>>页次:<b><%=currentpage%></b>/<b><%=Pcount%></b>页                                                                                                                                                                          
  &nbsp;   每页<b><%=Forum_Setting(11)%></b>   总数<b><%=totalrec%></b></font></td>                                                                                                                                                                          
  <td   valign=middle   nowrap><font   color=<%=Forum_body(13)%>><div   align=right><p>分页:    
  <%  
  if   currentpage   >   4   then  
  response.write   "<a   href=""?page=1"">[1]</a>   ..."  
  end   if  
  if   Pcount>currentpage+3   then  
  endpage=currentpage+3  
  else  
  endpage=Pcount  
  end   if  
  for   i=currentpage-3   to   endpage  
    if   not   i<1   then  
  if   i   =   clng(currentpage)   then  
                  response.write   "   <font   color=red>["&i&"]</font>"  
  else  
                  response.write   "   <a   href=""?page="&i&"""><b>["&i&"]</b></a>"  
  end   if  
    end   if  
  next  
  if   currentpage+3   <   Pcount   then    
  response.write   "...   <a   href=""?page="&Pcount&"""><b>["&Pcount&"]</b></a>"  
  end   if  
  %>  
  </p></div></font></td></tr></table>  
              </td>  
          </tr>  
      </table>  
  <Script>  
  function   CheckAll(form)     {  
      for   (var   i=0;i<form.elements.length;i++)         {  
          var   e   =   form.elements[i];  
          if   (e.name   !=   'chkall')               e.checked   =   form.chkall.checked;    
        }  
      }  
  </Script>  
  <%  
  end   if  
    rs.close  
    set   rs=Nothing  
  end   sub  
   
  sub   modify()  
  set   rs=server.createobject("adodb.recordset")  
  sql="select   *   from   [starcn]   where   ID="&   request("ID")  
  rs.open   sql,conn,1,1  
  if   rs.bof   and   rs.eof   then  
    response.write   "参数错误!"  
  else  
  %>  
  <script   src="include/ubbcode.js"></script>  
  <form   method="POST"   name=regform   action="?action=savemodify"   onsubmit="return   chkform()">  
  <input   type="hidden"   name="ID"   value="<%=request("ID")%>">  
  <input   type="hidden"   name="upfilerename">  
  <input   type="hidden"   name="comeurl"   value="<%=Request.ServerVariables("HTTP_REFERER")%>">  
  <table   width="95%"   border="0"   cellspacing="1"   cellpadding="3"     align=center>  
  <tr>    
              <td   height=25   align=left><B>说明</B>:查看用户留言。</td>  
  </tr>  
  </table>  
      <table   width="95%"   border="0"   cellspacing="1"   cellpadding="0"     align=center   class="tableBorder">  
          <tr>    
              <th   width="100%"     class="tableHeaderText"   height=27   colspan="4">查看留言    
              </th>  
          </tr>  
          <tr>    
              <td   width="7%"   class="forumrow"   height=1   align="right">  
                  <font   face="宋体"><strong><font   size="2">留言主题:</font></strong></font></td>                                                                                        
              <td   width="48%"   class="forumrow"   height=1   colspan="3"><%=rs("mess_title")%></td>                                                                                        
          </tr>          
           
          <tr>    
              <td   width="7%"   class="forumrow"   height="1">  
                  <p   align="right">&nbsp;<font   size="2"   face="宋体"><b>留言作者:</b></font></p></td>                                                                                                        
              <td   width="48%"   class="forumrow"   height="1"   colspan="3"><%=rs("mess_auther")%></td>                                                                                                        
          </tr>  
  <tr>  
  <td   width=7%   class="Forumrow"   align="right"   height="1">  
  <font   face="宋体"   size="2"><strong>电子邮件:</strong></font></td>  
  <td   width=48%   class="Forumrow"   height="1"   colspan="3"><%=rs("mess_email")%></td></tr>  
  <tr>  
  <td   width=7%   class="Forumrow"   align="right"   height="92"   valign="top">  
  <font   face="宋体"   size="2"><strong>留言内容:</strong></font></td>  
  <td   width=48%   class="Forumrow"   height="92"   valign="top"   colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;<%=rs("mess_comment")%></td>  
  </tr>  
  <tr>  
  <td   width=7%   class="Forumrow"   align="right"   height="1">  
  <font   face="宋体"   size="2"><strong>来自:</strong></font></td>  
  <td   width=16%   class="Forumrow"   height="1"><%=rs("mess_date")%></td>  
  <td   width=4%   class="Forumrow"   height="1">日期:</td>  
  <td   width=28%   class="Forumrow"   height="1"><%=rs("mess_date")%></td>  
  </tr>  
          <tr   bgcolor=<%=Forum_body(3)%>>    
              <td   width="150%"   height="1"   colspan="4"   class=Forumrow><div   align="center"><input   type=button   name=submit   value='返回'   onclick="window.history.go(-1);"></div>   </td>  
          </tr>  
      </table>  
  </form>  
  <Script>  
  function   chkform()  
  {  
      if(document.regform.Name.value=="")    
    {  
                  alert   ('请在输入产品名称。');  
                  document.regform.Title.focus();  
                  return   false;  
              }  
  }  
  </Script>  
  <%  
  end   if  
  rs.close  
  set   rs=Nothing  
  end   sub  
  %>  
   
   
  参考参考Top

相关问题

  • 分页???
  • 分页
  • ===分==========================页====
  • 分页技术
  • 关于分页……
  • ADO分页?
  • 分页代码
  • 分页问题
  • ASP分页
  • 分页:absolutepage=-1???

关键词

  • 主题
  • 用户
  • 作者
  • 留言
  • 查看
  • 日期

得分解答快速导航

  • 帖主:chfeijj

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo