This paging uses the 0 cursor, which is Rs.Open Sql,Conn,0,1. But it doesn’t feel much faster, 10
The paging time for 10,000 pieces of data is more than 300 milliseconds.
<%
Class Page
Private CurrPage
Private PageN
Private UrlStr
Private TempStr
Private ErrInfo
PrivateIsErr
Private TotalRecord
Private TotalPage
Public PageRs
Private TempA(11)
Private TempB(8)
'------------------------------------------------ ----------
Private Sub Class_Initialize()
CurrPage=1'//The current page is displayed as the first page by default
PageN=10'//By default, 10 pieces of data are displayed on each page
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
'------------------------------------------------ ----------
'//Get the current page number
Public Property Let CurrentPage(Val)
CurrPage=Val
End Property
Public Property Get CurrentPage()
CurrentPage=CurrPage
End Property
'//Get the number of items displayed on each page
Public Property Let PageNum(Val)
PageN=Val
End Property
Public Property Get PageNum()
PageNum=PageN
End Property
'//Get URL
Public Property Let Url(Val)
UrlStr=Val
End Property
Public Property Get Url()
Url=UrlStr
End Property
'//Get the template
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 'Using client-side cursors can improve efficiency
PageRs.PageSize = PageN 'Define the number of records displayed on each page of the paging record set
PageRs.Open Sql,ConnObj,0,1
If Err.Number<>0 Then
Err.Clear
PageRs.Close
Set PageRs=Nothing
ErrInfo=ErrInfo&"Error creating or opening the recordset..."
IsErr=True
Response.Write ErrInfo
Response.End
End If
TotalRecord=PageRs.RecordCount'//What if it is 0?
If TotalRecord>=1 Then
'------------------------------------------------ ---------------------------start
'//Calculate the total number of pages, Ps, why not use PageRs.PageCount?
'If TotalRecord Mod PageN=0 Then
'TotalPage=PageRs.RecordCountPageN
'Else
'TotalPage=PageRs.RecordCountPageN
'TotalPage=Abs(Int(TotalPage))
'End If
TotalPage=PageRs.PageCount
'//Process the current received page number, the default is 1, so if it is not a numeric type, it will be 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
'------------------------------------------------ --------------------------Finish
Else
TotalPage=0
CurrPage=1
End If
'//
PageRs.AbsolutePage = CurrPage 'absolutepage: Set the pointer to the beginning of a page
PageRs.PageSize=PageN
End Sub
Private Sub Init()
'Private TempA(10)
TempA(1)="{N1}" '//Home page
TempA(2)="{N2}"'//Previous page
TempA(3)="{N3}"'//Next page
TempA(4)="{N4}"'//Last page
TempA(5)="{N5}"'//Current page number
TempA(6)="{N6}"'//Total number of pages
TempA(7)="{N7}"'//Number of items per page
TempA(8)="{N8}"'//Total number of articles
TempA(9)="{L}"'//Start of loop label
TempA(10)="{N}"'//Single label in loop: page number
TempA(11)="{L/}"'//End of loop label
'Private TempB(8)
TempB(1)="Home"
TempB(2)="Previous page"
TempB(3)="Next page"
TempB(4)="Last page"
TempB(5)=CurrPage'//Current page number
TempB(6)=TotalPage'//Total number of pages
TempB(7)=PageN'//Number of items per page
TempB(8)=TotalRecord'//Total number of articles
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&"The current style does not exist..."
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&"The current style does not exist..."
ShowStyle=ErrInfo
End Select
End Function
Private Function StyleA()
'Home Page Previous Page Next Page Last Page This page is page 1/20, a total of 20 pages, 10 articles per page, and a total of 200 articles.
'//Pagination example: [Home] [Previous page] [Next page] [Last page] [Page: 4/5 pages] [Total 86 articles/20 articles/page] Go to: _ page
'//Tag: {N1} {N2} {N3} {N4} || Total: {N8} records {N6} page currently is {N5} page {N7} records per page
If IsEmpty(TempStr) Then
ErrInfo=ErrInfo&"The template is empty..."
StyleB=ErrInfo
Exit Function
End If
DiM
If TotalPage>1 Then
If CurrPage>1 Then
M="<a href='"&UrlStr&"Page=1'>"&"Home"&"</a>"
TempStr=Replace(TempStr,"{N1}",M)
M="<a href='"&UrlStr&"Page="&CurrPage-1&"'>"&"Previous page"&"</a>"
TempStr=Replace(TempStr,"{N2}",M)
If CurrPage<TotalPage Then
M="<a href='"&UrlStr&"Page="&CurrPage+1&"'>"&"Next page"&"</a>"
TempStr=Replace(TempStr,"{N3}",M)
M="<a href='"&UrlStr&"Page="&TotalPage&"'>"&"Last Page"&"</a>"
TempStr=Replace(TempStr,"{N4}",M)
Else
TempStr=Replace(TempStr,"{N3}","Next page")
TempStr=Replace(TempStr,"{N4}","Last page")
End If
Else
TempStr=Replace(TempStr,"{N1}","Homepage")
TempStr=Replace(TempStr,"{N2}","Previous page")
M="<a href='"&UrlStr&"Page="&CurrPage+1&"'>"&"Next page"&"</a>"
TempStr=Replace(TempStr,"{N3}",M)
M="<a href='"&UrlStr&"Page="&TotalPage&"'>"&"Last Page"&"</a>"
TempStr=Replace(TempStr,"{N4}",M)
End If
Else
TempStr=Replace(TempStr,"{N1}","Homepage")
TempStr=Replace(TempStr,"{N2}","Previous page")
TempStr=Replace(TempStr,"{N3}","Next page")
TempStr=Replace(TempStr,"{N4}","Last page")
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()
'Homepage|< 1 2 3 4 5 6 7 >| Last page
'//Tag:{N1} {N2} {L}{N}{L/}{N3}{N4}
If IsEmpty(TempStr) Then
ErrInfo=ErrInfo&"The template is empty..."
StyleB=ErrInfo
Exit Function
End If
Dim ForceNum,BackNum'//The number displayed in front and behind the current page
ForceNum=5
BackNum=4
DiM
'//front page
M="<a href='"&UrlStr&"Page=1'>"&TempB(1)&"</a>"
TempStr=Replace(TempStr,"{N1}",M)
'//Last page
M="<a href='"&UrlStr&"Page="&TempB(6)&"'>"&TempB(4)&"</a>"
TempStr=Replace(TempStr,"{N4}",M)
'//Previous page
M="|<"
If CurrPage-1>=1 Then
M="<a href='"&UrlStr&"Page="&CurrPage-1&"'>"&"|<"&"</a>"
End If
TempStr=Replace(TempStr,"{N2}",M)
'//Next page
M=">|"
If CurrPage+1<=TotalPage Then
M="<a href='"&UrlStr&"Page="&CurrPage+1&"'>"&">|"&"</a>"
End If
TempStr=Replace(TempStr,"{N3}",M)
'//Remove the loop label
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&"Error in loop label..."
StyleB=ErrInfo
Exit Function
End If
N3=Mid(TempStr,N1,N2-N1+4)'//Storage templates including {L}{L/} loop tags
N4=Replace(N3,"{L}","")'//Storage templates that do not include {L}{L/} loop tags
N4=Replace(N4,"{L/}","")
'//Page number list
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()
'Homepage|< |<< 1 2 3 4 5 6 7 >>| >| Last page
'//This style is modified based on StyleB, adding two tags: {N9} Previous 10 pages {N10} Next 10 pages
'//Tag:{N1}{N2}{N9}{L}{N}{L/}{N10}{N3}{N4}
Dim T
T=StyleB()
'//The first ten pages
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()
'//This style is modified based on StyleC
'//Total {N8} records {N6} page currently is {N5} page {N7} records per page
'//Homepage|< |<< 1 2 3 4 5 6 7 >>| >| Last page
'//Tag:{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
%>