分页显示函数

<!--#include file="conn.asp"-->

<style type="text/css">
<!--
ul{border:0; margin:0; padding:0;}
#pagination LI{border:soLId 1px #DDDDDD;margin-right:1px;float:left;}
#pagination a{text-decoration: none;}
#pagination .active{color:#ff0084;font-weight:bold;display:block;float:left;padding:5px 6px;}
#pagination .Linkoff{color:#CCCCCC;display:block;float:left;padding:5px 6px;}
#pagination .pagetotle{color:#0063e3;font-weight:bold;display:block;float:left;padding:5px 6px;}
#pagination a:LInk,
#pagination a:visited {color:#0063e3;display:block;float:left;padding:5px 6px;text-decoration:none;}
#pagination a:hover{text-decoration:none;background-color: #CCC;}
-->
</style>

<%'简单分页,两次读库操作
Dim Ts_ID,Ts_Table,Ts_Field,Ts_order

Ts_ID="ID"  '索引ID
Ts_Table="table1" '表名
Ts_Field="id,aaaa,bbbb,cccc" '字段名
Ts_Order="ORDER BY ID Desc"   '倒序

dim Ts_Page_Count,Ts_Page_Per,Ts_Page_Cnts,Page
Ts_Page_Per=5 '每页显示数
Ts_Page_Cnts=4  '每页显示的页数


Page = Request.QueryString("Page") '得到当前页码
if Page="" or Not IsNumeric(Page) then Page=1
Page =int(Page)
'从数据库中读取统计当前记录总数
set Rs=Server.CreateObject("Adodb.Recordset")

'sql= "SELECT Count("&Ts_ID&") FROM "&Ts_Table&" "
'Rs.Open SQL,Conn,0,1,&H0001
'Ts_Page_Count = Rs(0)
'Rs.Close

Ts_Page_Count=Conn.Execute("select COUNT("&Ts_ID&") From "&Ts_Table&" ",0,1)(0)


' 显示页码的函数
Function Ts_Pagefun(Ts_Page_Count)
         Dim Ts_Page_k,Ts_Page_PageCnt,Ts_Page_Page2
         '计算页数
         If Ts_Page_Count/Ts_Page_Per = Int(Ts_Page_Count/Ts_Page_Per) then
         Ts_Page_PageCnt=int(Ts_Page_Count/Ts_Page_Per)
         else
         Ts_Page_PageCnt=int(Ts_Page_Count/Ts_Page_Per)+1
         end if
   '最大分页
         if Page>Ts_Page_PageCnt then Page=Ts_Page_PageCnt '
    
         Ts_Page_Page2= int(Page/Ts_Page_Cnts)
         if Page/Ts_Page_Cnts>Ts_Page_Page2 then Ts_Page_Page2=Ts_Page_Page2+1
  
         Ts_Page_k=Ts_Page_Page2*Ts_Page_Cnts
         if Ts_Page_k>Ts_Page_PageCnt then Ts_Page_k=Ts_Page_PageCnt              
         '打出页码
               Response.Write ("有"&Ts_Page_Count&" 条 "& Page &"/"& Ts_Page_PageCnt &"页 分页")
               if Ts_Page_Page2>1 then
               Response.Write ("<a href='?Page=1'><font face=webdings>9</font></a>")
               Response.Write (" <a href='?Page="& Ts_Page_Page2*Ts_Page_Cnts-Ts_Page_Cnts &"'><font face=webdings>3</font></a>")
               end if
               For Ts_Page_m =Ts_Page_Page2*Ts_Page_Cnts-(Ts_Page_Cnts-1) To Ts_Page_k
               Response.Write (" [<a href='?Page="& Ts_Page_m &"'>"& Ts_Page_m &"</a>]")
               Next
               if Ts_Page_Page2*Ts_Page_Cnts < Ts_Page_PageCnt then
               Response.Write (" <a href='?Page="&Ts_Page_m&"'><font face=webdings>4</font></a>")
               Response.Write (" <a href='?Page="&Ts_Page_PageCnt&"'><font face=webdings>:</font></a>")
               end if
End Function

' 显示页码的函数
Function Ts_PageTurn(Ts_Page_Count)
 Dim Ts_Page_PageCnt,StartPage,EndPage
 '计算页数
 If Ts_Page_Count/Ts_Page_Per = Int(Ts_Page_Count/Ts_Page_Per) then
 Ts_Page_PageCnt=int(Ts_Page_Count/Ts_Page_Per)
 else
 Ts_Page_PageCnt=int(Ts_Page_Count/Ts_Page_Per)+1
 end if            
 
 '打出页码
 Response.Write ("<UL id=""pagination"">"&vbcrlf)
 Response.Write ("<LI class=""pagetotle"">共"&Ts_Page_Count&"条 "& Page &"/"& Ts_Page_PageCnt &"页</LI>")
      
 if Page>1 then
 Response.Write ("<LI><a href='?Page=1'>首页</a></LI>"&vbcrlf)
 Response.Write ("<LI><a href='?Page="& (Page-1) &"'>上一页</a></LI>"&vbcrlf)
 Else
 Response.Write ("<LI class=""LInkoff"">首页</LI>"&vbcrlf)
 Response.Write ("<LI class=""LInkoff"">上一页</LI>"&vbcrlf)
 end if
      
 StartPage = Page - Int(Ts_Page_Cnts/2)
 EndPage = Page + Int(Ts_Page_Cnts/2)
 
 If (Page - Int(Ts_Page_Cnts/2)) < 1 then
  StartPage = 1
  EndPage = Ts_Page_Cnts + 1
 End If
 If (Page + Int(Ts_Page_Cnts/2)) >= Ts_Page_PageCnt Then
  EndPage = Ts_Page_PageCnt
  StartPage = EndPage - Ts_Page_Cnts
 End If
 '连续分页
 For Ts_Page_m = StartPage to EndPage
  if Ts_Page_m = Page then
  Response.Write ("<LI class=""active"">"& Ts_Page_m &"</LI>"&vbcrlf)
  else
  Response.Write ("<LI><a href=""?page="& Ts_Page_m &""">"& Ts_Page_m &"</a></LI>"&vbcrlf)
  end if
 Next              
 if Page < Ts_Page_PageCnt then
 Response.Write ("<LI><a href=""?page="&Page+1&""">下一页</a></LI>"&vbcrlf)
 Response.Write ("<LI><a href=""?page="&Ts_Page_PageCnt&""">尾页</a></LI>"&vbcrlf)
 Else
 Response.Write ("<LI class=""LInkoff"">下一页</LI>"&vbcrlf)
 Response.Write ("<LI class=""LInkoff"">尾页</LI>"&vbcrlf)
 end if
 Response.Write ("</ul>")
End Function

 '打开记录集
 sql="select  "&Ts_Field&" From "&Ts_Table&" "&Ts_order&" "
 Rs.Open sql,Conn,1,1,&H0001
'根据分页参数获取当前页面纪录
 Rs.AbsolutePosition=Rs.AbsolutePosition+((Abs(Page)-1)*Ts_Page_Per)
%>
<%=Ts_PageTurn(Ts_Page_Count)%>


<br />
<br />

       <%
       iPage=0
       do while not rs.eof and iPage < Ts_Page_Per
       iPage=iPage+1
   
    response.Write(rs("aaaa")&"</br>")
       %>

        <%
        rs.movenext
                  loop
        Rs.Close '每用完一次RS,就关一次
                     '每页最后,关闭和释放内存
        Set Rs = Nothing
        conn.close
        set conn=nothing
%>

<%
EndTime=timer
Response.Write "<br><div aLIgn=""center"">执行时间"&(EndTime-StarTime)*1000&"毫秒</div><br>"
%>

 

posted @ 2009-07-05 22:05  DELPHI&.NET初学者[TECSOON WENDAY]  阅读(188)  评论(0编辑  收藏  举报