网络编程
位置:首页>> 网络编程>> Asp编程>> asp 分页函数,可以显示 1,2,3,4,5... 前十页,后十页,下一页,上一页

asp 分页函数,可以显示 1,2,3,4,5... 前十页,后十页,下一页,上一页

  发布时间:2009-07-05 18:34:00 

标签:asp,分页,函数

<%   
   SoFia_DbName="jiaoyou" '修改此处为你的SQL   Server   数据库名称   
           YourServer   =   "seven" '修改此处为你的Sql   Server数据库地址   
           YourUid     =   "sa" '修改此处为你的数据库用户名   
           YourPassword   =   "struts" '修改此处为你的数据库密码             
           Connstr   =   "Driver={SQL   Server};Server="&YourServer&";Uid="&YourUid&";

Pwd="&YourPassword&";Database="&SoFia_DbName   
           Set   Conn=Server.CreateObject("ADODB.CONNECTION")   
   '         On   Error   Resume   Next   
           Conn.Open   Connstr   
           If   Err<>0   Then   
                   err.Clear   
                   Set   Conn   =   Nothing   
                   Response.Write   "<div   align=center><br><br><br>连接SqlServer数据库出错,请检查相关设置……</div>"   
                   Response.End           
           End   If   
    
   set   rs   =   server.CreateObject("adodb.recordset")   
   rs.open   "select   *   from   userInfo   order   by   id   desc",conn,1,1   
   if   not(rs.Eof   and   rs.Bof)   Then   
   page   =   trim(request.form("page"))   
   if   page   =   ""   then   page   =   trim(request.QueryString("page"))   
   if   Not(IsNumeric(page))   or   page   =   "0"   then   page   =   1   
   rs.pageSize   =   30 '设置每页的个数   
   strFile   =   "?" '设置当前页面的名称   
   pageCount   =   rs.pageCount   
   if   len(page)   >   4   then   page   =   pageCount   
   if   Cint(page)   >   Cint(pageCount)   then   page   =   pageCount   
   rs.absolutepage   =   page   
   for   i   =   1   to   rs.pagesize   
   if   rs.eof   then   exit   for   
   Response.Write   (Rs("username")&"<br>")&VbNewline   
   rs.MoveNext   
   Next'i   
   End   if%>   
    
   <%   
   Response.Write   ("<table   border=0   align=center   cellpadding=0   cellspacing=0><tr><td>")&VbNewline   
   if   pagecount   <   1   then   pagecount   =   1   
   response.Write   ("第"&page&"页/共"&PAGECOUNT&"页,每页"&rs.pageSize&"条/共"&rs.recordCount&"条记录</td><td> ")   
   beginpage   =   1   
   endpage   =   CInt(pagecount)   
   page   =   CInt(page)   
   if   pagecount   >=   9   then   
   if   page   >=   5   then   
   beginpage   =   page   -   4   
   if   page   <=   (pagecount   -   4)   then   
   endpage   =   page   +   4   
   else   
   endpage   =   pagecount   
   beginpage   =   pagecount   -   4   
   end   if   
   else   
   beginpage   =   1   
   endpage   =   9   
   end   if   
   end   if   
   if   beginpage>1   then   response.write   "<a   title=首页   href='"&strFile&logpage&"'><font   face=webdings>9</font></a>"   
   for   j   =   beginpage   to   endpage   
   if   j   =   page   then   
   response.write"[<b>"&j&"</b>] "   
   else   
   response.write"[<a   href='"&strFile&"page="&j&logpage&"'>"&j&"</a>] "   
   end   if   
   next   
   if   endpage   <   pagecount   then   response.write   ("<a   title=末页   href='"&strFile&"page="&pagecount&logpage&"'><font   face=webdings>:</font></a>")   
   Response.Write   ("</td><form   name='changepage'   method='post'   action='"&strFile&"'><td   align='right'> ")&VbNewline   
   Response.Write   ("<select   name='page'   onchange='document.changepage.submit();'>")&VbNewline   
   For   i=0   To   pagecount     
   If   i<>pagecount   Then     
   Response.Write   ("<option   value='"&i+1&"'")   
   If   page=i+1   Then   Response.Write   ("   selected")   
   Response.Write   (">"&i+1&"</option>")&VbNewline   
   End   If   
   Next   
   Response.Write   ("</select></td></form></tr></table>")   
   rs.close   
   set   rs   =   nothing   
   %>

方法二:
<!--#include   file="conn.asp"-->   
   <%   
   dim   ip   
   ip=Request.ServerVariables("REMOTE_ADDR")   
   %>   
   <html>   
    
   <head>   
   <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">   
   <link   href="css.css"   rel="stylesheet"   type="text/css">   
   <title>LCD软件管理系统   全部软件</title>   
   <script   language="JavaScript">   
   function   deletes()   
   {   
   if(   confirm("你确定要删除这些文件吗?\n"))   
   {return   true;   
   }   
     return   false;   
   }   
   </script>   
    
   </head>   
    
   <body   leftmargin="0"   topmargin=5>   
   <center>   
   <h3><font   color=red   face="幼圆">全部软件列表</font></h3>   
    
   <%   
   set   rs=server.createobject("adodb.recordset")   
   sql="select   *   from   info   where   used=0   and   pn<>'0'   order   by   pn"   
   rs.open   sql,conn,1,1   
   %>   
   <table   width="870"   border="0"   cellpadding="0"   cellspacing="0"   style="border-collapse:   collapse"   bordercolor="#111111"   class=text>   
   <tr><td   colspan="6">   
   共有:<font   size=2   color=red><b> <%=rs.recordcount%> </b></font><font   size=2>个软件</font>   
   <%     
   MMaxPerPage=15   
   rs.PageSize=MMaxPerPage     
   if   trim(request("Page"))<>""   then   
   CurrentPage=CInt(request("Page"))   
       if   CurrentPage>rs.PageCount   then   
   CurrentPage=rs.PageCount   
       end   if   
   else   
   CurrentPage=1   
   end   if   
    
    
   ttotalPut=rs.RecordCount   
       if   CurrentPage<>1   then   
   if   (CurrentPage-1)*MMaxPerPage<ttotalPut   then   
   rs.Move(CurrentPage-1)*MMaxPerPage   
                                   bookmark=rs.Bookmark   
   end   if   
       end   if       
    
    
    
   if   (ttotalPut   mod   MMaxPerPage)=0   then   
   mm=ttotalPut\MMaxPerPage                   
   else   
   mm=ttotalPut\MMaxPerPage+1   
   end   if   
    
    
   if   (ttotalPut   mod   (MMaxPerPage*10))=0   then   
   nn=ttotalPut\(MMaxPerPage*10)                       
   else   
   nn=ttotalPut\(MMaxPerPage*10)+1   
   end   if   
   %>   
    
    
                 <%   
                           if   (CurrentPage   mod   10)=0   then   
                 kk=CurrentPage\10-1   
           else     
                 kk=CurrentPage\10   
                           end   if   
    
                           if   nn>1   and   CurrentPage>10   then   
                 Response.Write   "<b><a   href='all.asp?s1="&request("s1")&"&s2="&request("s2")&"&s3="&request("s3")&"&s4="&request("s4")&"&andor="&request("andor")&"&ss="&request("ss")&"&page="+CStr((kk-1)*10+1)+"'>Pre.</a></b>"   
           end   if   
    
    
           for   ii=1   to   10   
   jj=kk*10+ii   
             if   jj<=mm   then   
                   if   jj=CurrentPage   then   
         Response.Write   "   <font   color=red>"+CStr(jj)+"</font>"   
                   else   
         Response.Write   "   <b>"+"<a   href='all.asp?s1="&request("s1")&"&s2="&request("s2")&"&s3="&request("s3")&"&s4="&request("s4")&"&andor="&request("andor")&"&ss="&request("ss")&"&page="+CStr(jj)+"'>"+CStr(jj)+"</a></b>"   
                   end   if   
             end   if   
           next   
            
                           Response.Write   "   "   
           if   kk<nn-1   then   
                 Response.Write   "   <b>"+"<a   href='all.asp?s1="&request("s1")&"&s2="&request("s2")&"&s3="&request("s3")&"&s4="&request("s4")&"&andor="&request("andor")&"&ss="&request("ss")&"&page="+CStr((kk+1)*10+1)+"'>Next</a></b>"   
    
           end   if   
   %></td></tr></table>   
   <table   width="870"   border=0   cellpadding=0   cellspacing=0   class=text>   
   <tr>   
                           <td   width=30>ID</td>   
   <td   width=110>料号</td>   
   <td   width=190>显示屏</td>   
   <td   width=100>主板</td>   
   <td   width=180>语言</td>   
   <td   width=110>LOGO</td>   
   <td   width=50>版本</td>   
   <td   width=60>文件大小</td>   
   <td   width=40>   </td>   
   </tr>   
   <tr   height="1"   bgcolor="#689ACE"><td   colspan="9"></td></tr>   
    
   <%   
                       k=0   
                       for   y=(page-1)*15+1   to   (page-1)*15+15   
                       do   while   not   rs.EOF   and   i<MMaxPerPage   
    
   %>   
   <tr   <%if   i   mod   2   then%>   bgcolor=#DEE3F7   <%End   if%>   height=25>   
           <td   width=30>   
   <%   
   Set   Fs   =   Server.CreateObject("Scripting.FileSystemObject")   
   If   Fs.FileExists(server.mappath("uploadfile/"&rs("filepath")))   Then   
   Response.Write   "<font   color=gray>"&rs("id")&"</font>"   
   else   
                           Response.Write   "<font   color=red>"&rs("id")&"</font>"   
   end   if   
   %></td>   
   <td   width=110><%=rs("pn")%></td>   
   <%set   rs1=server.createobject("adodb.recordset")   
                           sql1="select   *   from   item   where   id="&rs("panel")   
                           rs1.open   sql1,conn,1,1%>   
   <td   width=190><%=rs1("item")%></td>   
   <%set   rs1=server.createobject("adodb.recordset")   
                           sql1="select   *   from   item   where   id="&rs("mb")   
                           rs1.open   sql1,conn,1,1%>   
   <td   width=100><%=rs1("item")%></td>   
   <%set   rs1=server.createobject("adodb.recordset")   
                           sql1="select   *   from   item   where   id="&rs("lang")   
                           rs1.open   sql1,conn,1,1%>   
   <td   width=180><%=rs1("item")%></td>   
   <td   width=110><%If   IsNumeric(Left(rs("logo"),8))   then%><img   src="LogoFile/<%=rs("logo")%>"   width=100   border=0   vspace="1"><%else%><%=rs("logo")%><%End   if%></td>   
   <td   width=50><%=rs("vers")%></td>   
   <td   width=60><%=Round(rs("filesize")/1024,2)%>   K</td>   
   <td   width=40><a   href=#   onclick=openwin('list.asp?id=<%=rs("id")%>')>详细</a></td>   
   </tr>   
    
   <%   
   i=i+1   
   rs.MoveNext     
   loop   
   next   
   %>   
   <tr   height="1"   bgcolor="#689ACE"><td   colspan="9"></td></tr>   
   </table>   
    
   </body>   
    
   </html>


0
投稿

猜你喜欢

  • 有时需要获取远程网站的某些信息,而服务器又限制了GET方式,只能通过POST数据提交,这个时候我们可以通过asp来实现模拟提交post数据,
  • 呃,看到这个标题,我们可以首先将IE系浏览器无视了。我承认,我是有极简主义倾向的,我希望能够使用最少的代码和图片做更多的事情。虽然CSS3仅
  • 你可以通过自定义函数接口 (UDF)来添加函数。自定义函数被编译为目标文件,然后用CREATE FUNCTION 和DROP FUNCTIO
  • 这个是今年年初写的一篇,拿出来温习下。指针让程序结构变得混乱,也让程序执行效率提高,因此在oo的语言中不提倡指针的使用,使得程序结构清晰易读
  • 判断某一个表的记录总数,对于一个开发者来说是最再常见不过的事,我想大家都常用的作法就是:以下为引用的内容:select count(*) f
  • 本文介绍了一些JavaScript常用到得表单验证函数,方便大家使用。 判断是否为整数,是则返回true,否则返回falsefun
  • 根据一般做法的话,导出部分字段时没有办法生成格式化XML文件,所以导入时就没有办法格式化导入数据。 我想到两点,1.手工修改格式化XML文件
  • 1、最郁闷的发现!!先看代码:<style>#a #b #c span{color:red;}#b #c span{color:
  • 本站收集的js实现的同步动态显示当前日期,时间和星期几的代码,我经常用在自己做的企业网站的后台,方便嘛。效果可以看看本站的首页,呵呵!而且代
  • 前不久听到这样一个面试的故事:面试官:你准备在我们公司做些什么事情?(大致这个意思)面试人:我准备在公司做网站重构,把原来是table的页面
  •   很早以前就说过,IE8的标准模式已经不再支持滤镜了,不过IE仍然留了一条后路,你可以在CSS中这样写滤镜:-ms-filter
  • 这是早上找了点时间写了一个利用404错误达到静态态效果的类,准备在HTTP://PJSKIN.MYSUC.COM中使用的。不过现在没时间去弄
  • 1.intersect为取多个查询结果的交集;2.查询两个基本时间段内表记录的SQL语句;select * from shengjibiao
  • 如果只是因为浏览者改变了浏览器的设置,或者因为浏览器不兼容,使自己精心制作的网页变得“面目全非”,那多令人沮丧!下面我们以网页爱好者的常用工
  • 下面,我们就从当前时间来取得随机数,调用的时候用包含文件就可以了:<!--#INCLUDE VIRTUAL="/q
  • 一次又一次的,我发现,那些有bug的Javascript代码是由于没有真正理解Javascript函数是如何工作而导致的(顺便说一下,许多那
  • 有时候想为我们的网页提供多语言支持,如果一种语言用一张网页来做实在太麻烦了,幸好Google提供了语言工具功能,下面介绍如何利用它来实现网页
  • 先声明一下,这是本人在某个项目中用到的,本人自己写的,如有雷同纯属巧合。同时也欢迎高人指正。这种星级的投票效果很常见,但是目前线上大多都是通
  • MySQL的Explain命令用于查看执行效果。虽然这个命令只能搭配select类型语句使用,如果你想查看update,delete类型语句
  • 最近在做搜索设计时,发现了两个容易纠结的小问题,在这里谈谈自己的一些分析。问题一:提交的关键字是哪个?凡客的这个例子中,搜索建议“时尚斜拉链
手机版 网络编程 asp之家 www.aspxhome.com