ASP article common paging function

Source: Internet
Author: User

<%
'------------------------------------------------------------

'------------------------------------------------------------
CLASS pagination
Public PageSize ' How many records are displayed per page
Public AbsolutePage ' current page
Public BaseURL ' URL of the page to jump
Public basequerystring ' Page the original querystring
Public rst ' converted Recordset
Public Pagelistcount ' The number of pages listed below ...
Public Beginposition ' Where does the record start
Public Endposition '
Public Pagelistforreturn ' Add by Jeanun 2008.11.13

PRIVATE Sub Class_Initialize ' constructor.
PageSize =20
Absolutepage=request. QueryString ("page")
BaseURL =request. ServerVariables ("URL")
basequerystring = ""
Set Rst=server. CreateObject ("ADODB.") RecordSet ")
Pagelistcount =10

Dim o
For each o in Request.QueryString
If o<> "page" Then
basequerystring= basequerystring & O & "=" & Request.QueryString (O) & "&"
End If
Next

If not IsNumeric (AbsolutePage) Then
AbsolutePage = 1 ' can not be combined with the following conditions of judgment, otherwise, will be prompted to error, think Impassability!
End If

If trim (absolutepage) = "" or absolutepage<=0 Then
AbsolutePage = 1 ' note, not starting from 0. Don't believe you can try.
End If

Absolutepage=cint (AbsolutePage)
End Sub

Public SUB SetValue (PRST)
Set Rst=prst
Rst.pagesize =pagesize
If Cint (absolutepage) >rst.pagecount Then
Absolutepage=rst.pagecount
End If

If not rst.eof then
Rst.absolutepage=absolutepage
Beginposition =rst.absoluteposition
Else
Beginposition =0
End If
Endposition =beginposition+pagesize-1

If Endposition>rst.recordcount Then
Endposition=rst.recordcount
End If

End SUB

Public SUB PageList
If Rst.recordcount>0 Then
Dim startnum
Startnum=int ((absolutePage-1)/pagelistcount) *pagelistcount+1
' Formula: Int ((n-1)/col) *col+1 n given parameters col each row shows several numbers starting from 1, sequential rows

If Absolutepage<>1 Then
Response.Write ("<span class= ' inactivepage ' ><a href= '" &baseURL& "?page=1&" & basequerystring& "' title= ' first page ' >|&lt;</a></span>")
End If

If Startnum-pagelistcount>0 Then
Response.Write ("<span class= ' inactivepage ' ><a href= '" &baseURL& "? page=" & ( Startnum-pagelistcount) & "&" &baseQueryString& "' title= ' pre" &pageListCount& "page ' >&lt; &lt</a></span> ")
End If

For I=startnum to Startnum+pagelistcount-1

If I=absolutepage Then
Classname= "ActivePage"
Else
Classname= "Inactivepage"
End If

Response.Write ("<span class=" "&className&" ' ><a href= ' "&baseURL&"? page= "&i&" & "&baseQueryString&" ' > "&i&" </a></span> ")

If I>=rst.pagecount Then
Exit For
End If
Next

If Startnum+pagelistcount<=rst.pagecount Then
Response.Write ("<span class= ' inactivepage ' ><a href= '" &baseURL& "? page=" & startnum+ Pagelistcount) & "&" &baseQueryString& "' title= ' after" &pageListCount& "Page ' >&gt;&gt </a></span> ")
End If

If Absolutepage<>rst.pagecount Then
Response.Write ("<span class= ' inactivepage ' ><a href= '" &baseURL& "? page=" &rst.pagecount& " & "&baseQueryString&" ' title= ' last page ' >&gt;|</a></span> ')
End If
End IF
End Sub

Public Sub Pagelist4return
If Rst.recordcount>0 Then
Dim startnum
Startnum=int ((absolutePage-1)/pagelistcount) *pagelistcount+1
' Formula: Int ((n-1)/col) *col+1 n given parameters col each row shows several numbers starting from 1, sequential rows

If Absolutepage<>1 Then
Pagelistforreturn = "<span class= ' inactivepage ' ><a href= '" "&baseURL&"?page=1& "& basequerystring& "' title= ' first page ' >|&lt;</a></span>"
End If

If Startnum-pagelistcount>0 Then
Pagelistforreturn = Pagelistforreturn & "<span class= ' inactivepage ' ><a href= '" &baseURL& "? page=" & (Startnum-pagelistcount) & "&" &baseQueryString& "' title= ' before" &pageListCount& "Page ' > &lt;&lt</a></span> "
End If

For I=startnum to Startnum+pagelistcount-1

If I=absolutepage Then
Classname= "ActivePage"
Else
Classname= "Inactivepage"
End If

Pagelistforreturn = Pagelistforreturn & "<span class= '" &className& "' ><a href= '" &baseurl & "? page=" &i& "&" &baseQueryString& "' >" &i& "</a></span>"

If I>=rst.pagecount Then
Exit For
End If
Next

If Startnum+pagelistcount<=rst.pagecount Then
Pagelistforreturn = Pagelistforreturn & "<span class= ' inactivepage ' ><a href= '" &baseURL& "? page=" & (Startnum+pagelistcount) & "&" &baseQueryString& "' title= ' after" &pageListCount& "Page ' > &gt;&gt</a></span> "
End If

If Absolutepage<>rst.pagecount Then
Pagelistforreturn = Pagelistforreturn & "<span class= ' inactivepage ' ><a href= '" &baseURL& "? page=" &rst.pagecount& "&" &baseQueryString& "' title= ' last page ' >&gt;|</a></span> '
End If

Pagelistforreturn = Pagelistforreturn & "&nbsp;&nbsp;<input type= ' text ' id= ' gotopagevaluebox ' style= '" " width:20px "" "Onpropertychange=" "document.getElementById (' Gotopagelink '). href= '" &baseURL& "page= ' + This.value+ ' & ' &baseQueryString& "'" "Onchange=" "document.getElementById (' Gotopagelink '). href= '" & baseurl& "? page= ' +this.value+ ' &" &baseQueryString& "" "/> <span class= ' activepage ' ><a ID = ' Gotopagelink ' href= ' # ' >Go!</a></span> '
End IF
End Sub
End CLASS
%>

How to call the above paging type

<table width= "100%" border= "0" cellspacing= "0" cellpadding= "5"
 <tr>
  <td align= "Center" > A total <%=mypagination.rst.recordcount%> bar record current <%=mypagination.absolutepage%>/<%= Mypagination.rst.pagecount%> page
    <% mypagination.pagelist%></td>
 < /tr>
</table>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.