北斗公园

人類的全部才能無非是時間和耐心的混合物.---巴尔扎克

靠近我 | 首页| 新随笔| 联系| RSS 2.0 Feed| 登录

随笔 - 38, 评论 - 102, 引用 - 0, 文章 - 19
将此页加入网摘:
igooi 365Key Poco网摘 博采 
YouNote Niu.La 加加 VIVI 
<January 2008>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

留言簿(5)

随笔分类

随笔档案

文章分类

文章档案

相册

My MSN

关于我

我的朋友

搜索

  •  

最新评论 RSS

阅读排行榜

评论排行榜


Posted on 2005-07-02 13:10 Dipper 阅读(7176) 评论(6)  编辑 收藏

<!-- #i nclude file="../conn.asp" -->    //(Yoko:路径按自己的设置好)
<%
dim i,intPage,page,pre,last,filepath
  set rs = server.CreateObject("adodb.recordset")
   sql="select * from user order by user_ID desc"
      rs.PageSize = 20         //(Yoko:这里设定每页显示的记录数
      rs.CursorLocation = 3
      rs.Open sql,conn,0,2,1   //(Yoko:'这里执行你查询SQL并获得结果记录集
      pre = true
      last = true
      page = trim(Request.QueryString("page"))
     
      if len(page) = 0 then
                  intpage = 1
                  pre = false
      else
          if cint(page) =< 1 then
               intpage = 1
               pre = false
          else
              if cint(page) >= rs.PageCount then
                  intpage = rs.PageCount
                  last = false
              else
                   intpage = cint(page)
             end if
         end if
      end if
    if not rs.eof then
         rs.AbsolutePage = intpage
    end if
%>
<!--循环开始-->
 <%   
   for i=1 to rs.PageSize
     if rs.EOF or rs.BOF then exit for
  %>
      ..................
     //(Yoko:要循环显示的内容  )..................
      ...................
   <% 
     rs.movenext
    next
   %>
<!--循环体结束
分页部分:-->
 <table width="99%" border="1" cellpadding="2" cellspacing="2" borderColorLight=#808080 borderColorDark=#ffffff>
   <tr>
     <%if rs.pagecount > 0 then%>
     <td width="13%" align="left">当前页<%=intpage%>/<%=rs.PageCount%></td>
     <%else%>
    <td width="41%" align="left">当前页0/0</td><%end if%>
    <td width="46%" align="right"> <a href="本页.asp?page=1">首页</a>|
     <%if pre then%>
     <a href="本页.asp?page=<%=intpage -1%>">上页</a>| <%end if%>
     <%if last then%>
      <a href="本页.asp?page=<%=intpage +1%>">下页</a> |<%end if%>
      <a href="本页.asp?page=<%=rs.PageCount%>">尾页</a>|转到第
      <select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
      <%
       for i = 1 to rs.PageCount
       if i = intpage then%>
       <option value="本页.asp?page=<%=i%>" selected><%=i%></option>
     <%else%>
       <option value="本页.asp?page=<%=i%>"><%=i%></option>
        <%
          end if
        next
        %>
     </select>页</font>
    </td>
    </tr>
   </table>

 

 

下面是CSDN的:

<%

         dim Conn,RS,sqlStr,PageSize,RowCount,TotalPages,PageNo,Position,PageBegin,PageEnd

         set Conn= Server.CreateObject("ADODB.Connection")

         set RS = Server.CreateObject("ADODB.RecordSet")

         Conn.open "provider=sqloledb;data source=127.0.0.1;user id=sa;password=;initial catalog=zjydata"

         sqlStr="select * from Items order by iID"

         RS.open sqlStr,Conn,1,1

         PageSize=10

         If RS.RecordCount=0 then

         %>

                   <TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=1 style='font-size:9pt'>

                   <TR bgcolor=#003366 height=20px>

                   <TD align=center><font color=#FFFFFF>商品代码</font></TD>

                   <TD align=center><font color=#FFFFFF>商品名称</font></TD>

                   <TD align=center><font color=#FFFFFF>型号规格</font></TD>

                   <TD align=center><font color=#FFFFFF>计量单位</font></TD>

                   <TD align=center><font color=#FFFFFF>参考进价</font></TD>

                   <TD align=center><font color=#FFFFFF>参考售价</font></TD>

                   <TD align=center><font color=#FFFFFF>备注</font>

                   </TR>

                   <TR height=20px>

                   <TD align=center>没有任何商品信息!</TD>

                   <TR>

                   </TABLE>

         <%

         else

                   RS.PageSize = Cint(PageSize)

                   TotalPages=RS.PageCount

                   PageNo=Request.QueryString("PageNo")

                   if PageNo="" or PageNo<1 Then

                            PageNo = 1

                   end if

                   RS.AbsolutePage = PageNo

                  Position=RS.PageSize*PageNo

                   PageBegin=Position-RS.PageSize+1

                   if Position <RS.RecordCount then

                            PageEnd=Position

                   else

                            PageEnd= RS.RecordCount

                   end if

                   %>

                   <TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=1 style='font-size:9pt'>

                   <TR>

                   <TD width=20%>

                   <%

                            Response.Write "页:"& PageNo &" / "& TotalPages &" | 记录:"& PageBegin & " - " & PageEnd & " / " &RS.RecordCount

                   %>

                   </TD>

                   <TD align=right>

                   <%

                            if PageNo > 1 Then

                                     response.write "<a href=list.asp?PageNo=1>首页</a>&nbsp;<a href=list.asp?PageNo=" & (PageNo-1) & ">上页</a>&nbsp;"

                            end if

                            if  TotalPages > 1 and  cint(PageNo) <> cint(TotalPages) then

                                     response.write "<a href=list.asp?PageNo=" & (PageNo+1) & ">下页</a>&nbsp;<a href=list.asp?PageNo=" & TotalPages & ">末页</a>&nbsp;"

                            end if

                   %>

                   </TD>

                   </TR>

                   <TR bgcolor=#003366 height=20px>

                   <TD align=center width=20%><font color=#FFFFFF>商品代码</font></TD>

                   <TD align=center width=30%><font color=#FFFFFF>商品名称</font></TD>

                   <TD align=center width=8%><font color=#FFFFFF>型号规格</font></TD>

                   <TD align=center width=8%><font color=#FFFFFF>计量单位</font></TD>

                   <TD align=center width=8%><font color=#FFFFFF>参考进价</font></TD>

                   <TD align=center width=8%><font color=#FFFFFF>参考售价</font></TD>

                   <TD align=center width=18%><font color=#FFFFFF>备注</font></TR>

                   <%

                   RowCount = RS.PageSize

                   dim color1,color2

                   color1="#dddddd"

                   color2="#eeeeee"

                   Do While Not RS.EOF and RowCount > 0

                   Response.Write "<TR height=20px bgcolor="

                   %>

                   <%

                            if RowCount mod 2=0 then:response.write color1 else:response.write color2

                   %>

                   <%

                            Response.Write ">"

                   %>

                   <TD><span><a href=manage.asp?id=<%=rs(0)%>><% =RS("vCode")%></a></span></td>

                   <TD><span><% =RS("vName")%></span></td>

                   <TD><span><% =RS("vSpec")%></span></TD>

                   <TD><span><% =RS("vUnit")%></span></td>

                   <TD><span><% =RS("fInPrice")%></span></td>

                   <TD><span><% =RS("fOutPrice")%></span></TD>

                   <TD><span><% =RS("vDescription")%></span></td>

                   </TR>

                   <%

                   RowCount = RowCount - 1

                   RS.MoveNext

                   Loop

                   Conn.Close

                   set RS = nothing

                   set Conn = nothing

                   %>

                   <TR bgcolor=#003366 height=20px>

                   <TD align=center width=20%><font color=#FFFFFF>商品代码</font></TD>

                   <TD align=center width=30%><font color=#FFFFFF>商品名称</font></TD>

                   <TD align=center width=8%><font color=#FFFFFF>型号规格</font></TD>

                   <TD align=center width=8%><font color=#FFFFFF>计量单位</font></TD>

                   <TD align=center width=8%><font color=#FFFFFF>参考进价</font></TD>

                   <TD align=center width=8%><font color=#FFFFFF>参考售价</font></TD>

                   <TD align=center width=18%><font color=#FFFFFF>备注</font>

                   </TR>

                   <TR>

                   <TD>

                   <%

                            For i=1 to TotalPages

                                     if CInt(PageNo) = CInt(i) then

                                               response.write "["&i&"]"

                                     else

                                               response.write "&nbsp<a href=list.asp?PageNo="&i&">"&i&"</a>&nbsp"

                                     end if

                            Next

                   %>

                   </TD>

                   </TR>

                   </TABLE>

                   <%

         End if

%>

评论

# re: ASP分页代码

2005-11-29 17:51 by gh
gh

# re: ASP分页代码

2005-12-22 10:10 by jiutian
不知道能不能在加个条件,因为我用的分页代码,点击下一页时条件就丢失了,显示出错.
         sqlStr="select * from Items where id="&request("key")

# re: ASP分页代码

2006-05-05 16:10 by tina
不错啊,多谢了!

可是我用拼接字符串来实现组合查询,分页后只能显示第一页,要显示其他页就会出现错误类型:Microsoft OLE DB Provider for ODBC Drivers (0x80040E14),错误语句为: rs.open sql,conn,1,3,请问是怎么回事啊?

# re: ASP分页代码

2006-05-16 17:17 by rs
不错啊,多谢了! 

# re: ASP分页代码

2008-01-04 15:09 by masly
不错,又让我更进一步了~~~
标题  
姓名  
主页
内容   
请输入验证码:
*
  登录  使用高级评论  Top 订阅回复  取消订阅
[使用Ctrl+Enter键可以直接提交]