這個分頁使用的是0游標,也就是Rs.Open Sql,Conn,0,1。但是感覺也快不了多少,10
萬條數據的分頁時間300多豪秒之間
<%
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
Private Function StyleA()
'首頁 上一頁 下一頁 尾頁 本頁為第1/20頁,共20頁,每頁10條,文章總數200條
'//分頁樣例:[首頁] [上頁] [下頁] [尾頁] [頁次:4/5頁] [共86篇 20篇/頁] 轉到:_ 頁
'//標簽:{N1} {N2} {N3} {N4} || 共:{N8}條記錄 {N6}頁 當前為第{N5}頁 每頁{N7}條
If IsEmpty(TempStr) Then
ErrInfo=ErrInfo&"模板為空..."
StyleB=ErrInfo
Exit Function
End If
Dim M
If TotalPage>1 Then
If CurrPage>1 Then
M="<a href='"&UrlStr&"Page=1'>"&"首頁"&"</a>"
TempStr=Replace(TempStr,"{N1}",M)
M="<a href='"&UrlStr&"Page="&CurrPage-1&"'>"&"上一頁"&"</a>"
TempStr=Replace(TempStr,"{N2}",M)
If CurrPage<TotalPage Then
M="<a href='"&UrlStr&"Page="&CurrPage+1&"'>"&"下一頁"&"</a>"
TempStr=Replace(TempStr,"{N3}",M)
M="<a href='"&UrlStr&"Page="&TotalPage&"'>"&"尾頁"&"</a>"
TempStr=Replace(TempStr,"{N4}",M)
Else
TempStr=Replace(TempStr,"{N3}","下一頁")
TempStr=Replace(TempStr,"{N4}","尾頁")
End If
Else
TempStr=Replace(TempStr,"{N1}","首頁")
TempStr=Replace(TempStr,"{N2}","上一頁")
M="<a href='"&UrlStr&"Page="&CurrPage+1&"'>"&"下一頁"&"</a>"
TempStr=Replace(TempStr,"{N3}",M)
M="<a href='"&UrlStr&"Page="&TotalPage&"'>"&"尾頁"&"</a>"
TempStr=Replace(TempStr,"{N4}",M)
End If
Else
TempStr=Replace(TempStr,"{N1}","首頁")
TempStr=Replace(TempStr,"{N2}","上一頁")
TempStr=Replace(TempStr,"{N3}","下一頁")
TempStr=Replace(TempStr,"{N4}","尾頁")
End If
T=TempStr
T=Replace(T,"{N8}",TotalRecord)
T=Replace(T,"{N6}",TotalPage)
T=Replace(T,"{N5}",CurrPage)
T=Replace(T,"{N7}",PageN)
TempStr=T
StyleA=TempStr
End Function
Private Function StyleB()
'首頁 |< 1 2 3 4 5 6 7 >| 尾頁
'//標簽:{N1} {N2} {L}{N}{L/}{N3}{N4}
If IsEmpty(TempStr) Then
ErrInfo=ErrInfo&"模板為空..."
StyleB=ErrInfo
Exit Function
End If
Dim ForceNum,BackNum'//當前頁的前面和後面顯示個數
ForceNum=5
BackNum=4
Dim M
'//首頁
M="<a href='"&UrlStr&"Page=1'>"&TempB(1)&"</a>"
TempStr=Replace(TempStr,"{N1}",M)
'//尾頁
M="<a href='"&UrlStr&"Page="&TempB(6)&"'>"&TempB(4)&"</a>"
TempStr=Replace(TempStr,"{N4}",M)
'//前一頁
M="|<"
If CurrPage-1>=1 Then
M="<a href='"&UrlStr&"Page="&CurrPage-1&"'>"&"|<"&"</a>"
End If
TempStr=Replace(TempStr,"{N2}",M)
'//後一頁
M=">|"
If CurrPage+1<=TotalPage Then
M="<a href='"&UrlStr&"Page="&CurrPage+1&"'>"&">|"&"</a>"
End If
TempStr=Replace(TempStr,"{N3}",M)
'//取出循環標簽
Dim N1,N2,N3,N4,N5,N6
If InStr(TempStr,"{L}")>0 Then
N1=InStr(TempStr,"{L}")
End If
If InStr(TempStr,"{L/}")>0 Then
N2=InStr(TempStr,"{L/}")
End If
If N2<=N1 Then
ErrInfo=ErrInfo&"循環標簽出錯..."
StyleB=ErrInfo
Exit Function
End If
N3=Mid(TempStr,N1,N2-N1+4)'//儲存包括{L}{L/}循環標簽的模板
N4=Replace(N3,"{L}","")'//儲存不包括{L}{L/}循環標簽的模板
N4=Replace(N4,"{L/}","")
'//頁碼列表
Dim FirstPageNum,LastPageNum
If CurrPage-ForceNum<=1 Then
FirstPageNum=1
PageList=""
Else
FirstPageNum=CurrPage-ForceNum
PageList="... ..."
End If
If CurrPage+BackNum>=TotalPage Then
LastPageNum=TotalPage
PageList_2=""
Else
LastPageNum=CurrPage+BackNum
PageList_2="... ..."
End If
Dim I
For I=FirstPageNum To LastPageNum
If I=CurrPage Then
N5=Replace(N4,"{N}","<b>"&I&"</b>")
N6=N6&N5
Else
M="<a href='"&UrlStr&"Page="&I&"'>"&I&"</a>"
N5=Replace(N4,"{N}",M)
N6=N6&N5
End If
Next
TempStr=Replace(TempStr,N3,N6)
StyleB=TempStr
End Function
Private Function StyleC()
'首頁 |< |<< 1 2 3 4 5 6 7 >>| >| 尾頁
'//此風格在StyleB的基礎上修改,增加兩個標簽:{N9}上10頁 {N10}下10頁
'//標簽:{N1}{N2}{N9}{L}{N}{L/}{N10}{N3}{N4}
Dim T
T=StyleB()
'//前十頁
M="|<<"
If CurrPage-10>=1 Then
M="<a href='"&UrlStr&"Page="&CurrPage-10&"'>"&"|<<"&"</a>"
End If
T=Replace(T,"{N9}",M)
M=">>|"
If CurrPage+10<=TotalPage Then
M="<a href='"&UrlStr&"Page="&CurrPage+10&"'>"&">>|"&"</a>"
End If
T=Replace(T,"{N10}",M)
StyleC=T
End Function
Private Function StyleD()
'//此風格在StyleC的基礎上修改
'//共{N8}條記錄 {N6}頁 當前為第{N5}頁 每頁{N7}條
'//首頁 |< |<< 1 2 3 4 5 6 7 >>| >| 尾頁
'//標簽:{N1}{N2}{N9}{L}{N}{L/}{N10}{N3}{N4}
Dim T
T=StyleC()
T=Replace(T,"{N8}",TotalRecord)
T=Replace(T,"{N6}",TotalPage)
T=Replace(T,"{N5}",CurrPage)
T=Replace(T,"{N7}",PageN)
StyleD=T
End Function
End Class
%>