求一分页类的使用方法。
代码如下:
<%
Class Page
Private CurrPage
Private PageN
Private UrlStr
Private TempStr
Private ErrInfo
Private IsErr
Private TotalRecord
Private TotalPage
Public PageRs
Private TempA(11)
Private TempB(8)
'------------------------
Private Sub Class_Initialize()
CurrPage=1 '//默认显示当前页为第一页
PageN=10 '//默认每页显示10条数据
UrlStr= "? "
TempStr= " "
ErrInfo= "ErrInfo: "
IsErr=False
End Sub
Private Sub Class_Terminate()
If IsObject(PageRs) Then
PageRs.Close
Set PageRs=Nothing
End If
Erase TempA
Erase TempB
End Sub
'----------------------
'//获取当前页码
Public Property Let CurrentPage(Val)
CurrPage=Val
End Property
Public Property Get CurrentPage()
CurrentPage=CurrPage
End Property
'//获取每页显示条数
Public Property Let PageNum(Val)
PageN=Val
End Property
Public Property Get PageNum()
PageNum=PageN
End Property
'//获取URL
Public Property Let Url(Val)
UrlStr=Val
End Property
Public Property Get Url()
Url=UrlStr
End Property
'//获取模板
Public Property Let Temp(Val)
TempStr=Val
End Property
Public Property Get Temp()
Temp=TempStr
End Property
'------------------------
Public Sub Exec(Sql,ConnObj)
On Error Resume Next
Set PageRs=Server.CreateObject( "ADODB.RecordSet ")
PageRs.CursorLocation = 3 '使用客户端游标,可以使效率提高
PageRs.PageSize = PageN '定义分页记录集每页显示记录数
PageRs.Open Sql,ConnObj,0,1
If Err.Number <> 0 Then
Err.Clear
PageRs.Close
Set PageRs=Nothing
ErrInfo=ErrInfo& "建立或打开记录集错误... "
IsErr=True
Response.Write ErrInfo
Response.End
End If
TotalRecord=PageRs.RecordCount '//如果为0呢?
If TotalRecord> =1 Then
'----------------------------------------开始
'//计算总页数,Ps,为什么不用PageRs.PageCount呢?
'If TotalRecord Mod PageN=0 Then
'TotalPage=PageRs.RecordCount\PageN
'Else
'TotalPage=PageRs.RecordCount\PageN
'TotalPage=Abs(Int(TotalPage))
'End If
TotalPage=PageRs.PageCount
'//处理当前接收页码,默认的为1,所以不是数字类型的都会为1
If IsNumeric(CurrPage) Then
CurrPage=CLNg(CurrPage)
If CurrPage <1 Then CurrPage=1
If CurrPage> TotalPage Then CurrPage=TotalPage
Else
'//Dim M:M= " ":IsNumeric(M)=True
CurrPage=1
End If
'---------------------------------------结束
Else
TotalPage=0
CurrPage=1
End If
'//
PageRs.AbsolutePage = CurrPage 'absolutepage:设置指针指向某页开头
PageRs.PageSize=PageN
End Sub
Private Sub Init()
'Private TempA(10)
TempA(1)= "{N1} " '//首页
TempA(2)= "{N2} " '//上一页
TempA(3)= "{N3} " '//下一页
TempA(4)= "{N4} " '//尾页
TempA(5)= "{N5} " '//当前页码
TempA(6)= "{N6} " '//页码总数
TempA(7)= "{N7} " '//每页条数
TempA(8)= "{N8} " '//文章总数
TempA(9)= "{L} " '//循环标签开始
TempA(10)= "{N} " '//循环内单标签:页码
TempA(11)= "{L/} " '//循环标签结束
'Private TempB(8)
TempB(1)= "首页 "
TempB(2)= "上一页 "
TempB(3)= "下一页 "
TempB(4)= "尾页 "
TempB(5)=CurrPage '//当前页码
TempB(6)=TotalPage '//页码总数
TempB(7)=PageN '//每页条数
TempB(8)=TotalRecord '//文章总数
End Sub
Public Sub Show(Style)
If IsErr=True Then
Response.Write ErrInfo
Exit Sub
End If
Call Init()
Select Case Style
Case 1
Response.Write StyleA()
Case 2
Response.Write StyleB()
Case 3
Response.Write StyleC()
Case 4
Response.Write StyleD()
Case Else
ErrInfo=ErrInfo& "不存在当前样式... "
Response.Write ErrInfo
End Select
End Sub
Public Function ShowStyle(Style)
If IsErr=True Then
ShowStyle=ErrInfo
Exit Function
End If
Call Init()
Select Case Style
Case 1
ShowStyle= StyleA()
Case 2
ShowStyle= StyleB()
Case Else
ErrInfo=ErrInfo& "不存在当前样式... "
ShowStyle=ErrInfo
End Select
End Function
[解决办法]
有结果了,这样用。
sql = "SELECT ..... "
set p=new page
p.CurrentPage=读取页序,不设置是为首页
p.PageNum=页大小,不设置时默认为10
p.temp= "{N1} {N2} {N3} {N4} || 共:{N8}条记录 {N6}页 当前为第{N5}页 每页{N7}条 " '这是样式1的标签
p.Exec Sql,Conn
然后再用p.PageRs对象循环显示记录。
显示第一种模式页链接:p.Show 1
最后清空对象set p=nothing