ASP分页代码


  <%'=============分页定义开始,可放在数据库打开前或后
                 dim action
    action=request.QueryString("action")   
    Const MaxPerPage=6   '定义每页显示记录数,可根据实际自定义
       dim totalPut   
       dim CurrentPage
       dim TotalPages
       dim sql
        if Not isempty(request("page")) then
          currentPage=Cint(request("page"))
       else
          currentPage=1
       end if        
'=============分页定义结束%>
  <% '=============打开数据库数据表,要以这种方式打开   
set rs=server.CreateObject("adodb.recordset")  
rs.open "select * from buyok_produc  order by  ProdNum desc",conn,1,1
%>
  <%'=============分页类代码开始,需放在数据库数据表打开后
   
    if err.number<>0 then
    response.write "<p align='center'>数据库中暂时无数据</p>"
    end if    
      if rs.eof And rs.bof then
           Response.Write "<p align='center'>对不起,没有符合条件记录!</p>"
       else
totalPut=rs.recordcount
          if currentpage<1 then
              currentpage=1
          end if

          if (currentpage-1)*MaxPerPage>totalput then
         if (totalPut mod MaxPerPage)=0 then
           currentpage= totalPut \ MaxPerPage
         else
            currentpage= totalPut \ MaxPerPage + 1
         end if
          end if

           if currentPage=1 then
               showContent               
               showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""  
           else
              if (currentPage-1)*MaxPerPage<totalPut then
                rs.move  (currentPage-1)*MaxPerPage
               
                showContent
                 showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""  
            else
             currentPage=1
                showContent
                
                showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""  
                
           end if
        end if
           end if
'=============分页类代码结束%>
  <%'=============循环体开始
   sub showContent
   dim i
   i=0  
   do while not rs.eof%>
  <div id="probg">
    <div id="probgleft">
      <div id="prophoto"><img src="<%=rs("ImgPrev")%>" alt="<%=rs("ProdName")%>" width="100" height="80" border="0" /></div>
    </div>
    <div id="probgright"><%= rs("ProdName") %></div>
  </div>
  <!---此处为内容循环输出---->
  <%i=i+1
if i>=MaxPerPage then Exit Do
rs.movenext
loop
rs.close   '释放资源
set rs=nothing
 End Sub   
'=============循环体结束%>
<%'=============放置分页显示开始 
  Function showpage(totalnumber,maxperpage,filename)  
      Dim n      
    If totalnumber Mod maxperpage=0 Then  
     n= totalnumber \ maxperpage  
    Else
     n= totalnumber \ maxperpage+1  
    End If %>
 
<form method=Post action=<%=filename%>>
    <p align="center"> 
<%If CurrentPage<2 Then  %>
    首 页 上一页
    <% Else  %>
    <a href=<% = filename %>?page=1>首 页</a>
    <a href=<% = filename %>?page=<% = CurrentPage-1 %>>上一页</a> 
    <% End If 
    If n-currentpage<1 Then  %>
    下一页 尾 页
    <%  Else  %>
    <a href=<% = filename %>?page=<% = (CurrentPage+1) %>>下一页</a> 
    <a href=<% = filename %>?page=<% = n %>>尾 页</a>&nbsp;&nbsp;
    <% End If  %>
 页次:<b><font color=red><% = CurrentPage %></font></b>/<b><% = n %></b>页 <b><%=maxperpage%></b>个记录/页  共<b><%=totalnumber %></b>个记录    
转到:<select name="cndok" οnchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to n
if i = CurrentPage then%>
<option value="<% = filename %>?page=<%=i%>" selected>第<%=i%>页</option>  
<%else%>
<option value="<% = filename %>?page=<%=i%>">第<%=i%>页</option>  
<%
end if
next
%>
</select></font>
</form>
<%End Function 
'=============放置分页显示结束%>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值