该ASP分页类只是对ASP传统分页进行封装,使其分页操作更加简化,下面是代码:
==========Pager.asp=================================
<%
'--------------------------------------------------------------------
'名称:ASP分页类 v2009
'
'作者:zhengbi(QQ:124895502 Email:zhengbi888@yahoo.com.cn)
'
'仅供参考,你可以任意修改、传播;如果你对它进行了改良,希望你能给我一个
'副本,谢谢。
'--------------------------------------------------------------------
Class TurnPage
Dim sPageNo,sPageSize,sPageCount,sRecordCount,sAbsoluteRecord
Private Sub Class_Initialize()
sPageNo=Trim(Request.QueryString("PageNo"))
If sPageNo<>"" Then
sPageNo = Cdbl(sPageNo)
Else
sPageNo = 1
End If
sAbsoluteRecord = 1
End Sub
Public Sub GetRs(ByRef Conn,ByRef Rs,ByVal Sql,ByVal PageSize)
Rs.Open Sql,Conn,1,1
Rs.PageSize = PageSize
sPageSize = Rs.PageSize
sPageCount = Rs.PageCount
sRecordCount = Rs.RecordCount
If Not Rs.Eof Then Rs.AbsolutePage = sPageNo
End Sub
Public Function Eof()
If sAbsoluteRecord<=sPageSize Then
'sAbsoluteRecord = sAbsoluteRecord + 1
Eof = False
Else
Eof = True
End If
End Function
Public Sub MoveNext()
sAbsoluteRecord = sAbsoluteRecord + 1
End Sub
Public Sub GetPageList()
If sPageCount<=1 Then Exit Sub
Dim sURL,sTmp,sQUERY_STRING,p,n,i,a,b
sURL = Request.ServerVariables("URL")
sQUERY_STRING = Request.ServerVariables("QUERY_STRING")
sTmp = Split(sURL,"/")
sURL = sTmp(Ubound(sTmp))
If sQUERY_STRING <> "" Then sQUERY_STRING=Replace(sQUERY_STRING,"PageNo=" & sPageNo,"")
If sQUERY_STRING = "" Then
sURL = sURL & "?"
Else
sURL = sURL & "?" & sQUERY_STRING & "&"
End If
sURL = Replace(sURL,"&&","&")
p = sPageNo-1
n = sPageNo+1
If p<1 Then p = 1
If n>sPageCount Then n = sPageCount
a = sPageNo-5
b = sPageNo+5
If a<1 Then a = 1
If b>sPageCount Then b = sPageCount
Response.Write("<div class=""page_nav"">")
If sPageNo>1 Then Response.Write("<a href=""" & sURL & "PageNo=1"">第一页</a> <a href=""" & sURL &"PageNo=" & p & """>上一页</a>")
For i=a To b
If i = sPageNo Then
Response.Write( " " & i)
Else
Response.Write(" <a href=""" & sURL & "PageNo=" & i & """>[" & i & "]</a>")
End If
Next
If sPageNo < sPageCount Then Response.Write(" <a href=""" & sURL & "PageNo=" & n & """>下一页</a> <a href=""" & sURL & "PageNo=" & sPageCount & """>最后一页</a>")
Response.Write("</div>")
End Sub
End Class
%>
调用示例:
=============Conn.asp=============================
Dim Conn,ConnStr,Rs
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Db.mdb")Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnStr
Set Rs = Server.CreateObject("Adodb.RecordSet")
=============test.asp==============================
<!--#include file="Conn.asp"-->
<!--#include file="Pager.asp"-->
<%
Sql="select * from Ok3w_Article where IsPass=1 and IsDelete=0 order by IsTop desc,IsCommend desc,ID desc"
Set Page = New TurnPage
Call Page.GetRs(Conn,Rs,Sql,10)'创建Rs记录集,此处每页显示10条
Do While Not Rs.Eof And Not Page.Eof
%>
<a href="<%=Rs("ID")%>.html" target="_blank"><%=Rs("Title")%></a>
<%
Rs.MoveNext
Page.MoveNext
Loop
Rs.Close
%>
<%Call Page.GetPageList()'显示分页导航%>
<%
Set Page = Nothing
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
%>
比起常规分页类,操作相对要简单一点,不同之处,就是蓝色部份了。