ASP high Efficiency common paging class

Source: Internet
Author: User
Tags object end query servervariables
Efficiency | page-type <%
'=====================================================================
' Papgesize defines the number of records per page of pagination
' Getrs Returns a paging recordset this property is read-only
' Getconn get a database connection
' GetSQL get the query statement
' Procedure Method description
' ShowPage display the pager bar, the only common method
Cases
' Set mypage=new xdownpage ' Create object
' Mypage.getconn=conn ' Get database connection
' mypage.getsql= ' select * from ProductInfo ORDER by ID ASC
' Mypage.pagesize=5 ' Sets the record bar data for each page to 5
' Set Rs=mypage.getrs () ' returns to the recordset
' Mypage.showpage () ' Displays paging information, which can be used after set Rs=mypage.getrs ()
' Call anywhere, you can call multiple times
' For I=1 to Mypage.pagesize ' The next action is the same as manipulating a normal Recordset object
' If not rs.eof then ' this tag is to prevent last page overflow
' Response.Write Rs (0) & "
' Here's the way to customize the display.
' Rs.movenext
' Else
' Exit for
' End If
' Next
'=====================================================================
Const btn_first= "<font face=webdings>9</font>" defines the first page button display style
Const btn_prev= "<font face=webdings>3</font>" defines the previous-page button display style
Const btn_next= "<font face=webdings>4</font>" defines the next-page button display style
Const btn_last= "<font face=webdings>:</font>" defines the last-page button display style
Const xd_align= "Right" defines pagination information alignment
Const xd_width= "100%" Defines the paging information box size
Class Xdownpage
Private Xd_pagecount,xd_conn,xd_rs,xd_sql,xd_pagesize,str_errors,int_curpage,str_url,int_totalpage,int_ Totalrecord
'=================================================================
' PageSize Property
' Set the paging size of each page
'=================================================================
Public Property Let PageSize (Int_pagesize)
If IsNumeric (int_pagesize) Then
XD_PAGESIZE=CLNG (Int_pagesize)
Else
Str_error=str_error & "pagesize parameters are incorrect"
ShowError ()
End If
End Property
Public Property Get PageSize
If xd_pagesize= "" or (Not (IsNumeric (xd_pagesize)) Then
pagesize=10
Else
Pagesize=xd_pagesize
End If
End Property
'=================================================================
' Getrs Property
' Returns a paginated recordset
'=================================================================
Public Property Get Getrs ()
Set xd_rs=server.createobject ("Adodb.recordset")
Xd_rs.pagesize=pagesize
Xd_rs.open xd_sql,xd_conn,1,1
If not (xd_rs.eof and xd_rs. BOF) Then
If int_curpage>xd_rs. PageCount Then
Int_curpage=xd_rs. PageCount
End If
Xd_rs.absolutepage=int_curpage
End If
Set getrs=xd_rs
End Property
'================================================================
' Getconn get a database connection
'================================================================
Public Property Let Getconn (Obj_conn)
Set Xd_conn=obj_conn
End Property
'================================================================
' GetSQL get the query statement
'================================================================
Public Property Let GetSQL (Str_sql)
Xd_sql=str_sql
End Property
'==================================================================
' Initialization of the Class_Initialize class
' Initialize the value of the current page
'==================================================================
Private Sub Class_Initialize
'========================
' Set some parameters of the Summerside recognition value
'========================
xd_pagesize=10 ' Sets the default value of paging to 10
'========================
' Get when the previous value
'========================
If Request ("page") = "" Then
Int_curpage=1
ElseIf Not (IsNumeric (Request ("page")) Then
Int_curpage=1
ElseIf CInt ("page") <1 Then
Int_curpage=1
Else
Int_curpage=cint Trim (Request ("page"))
End If
End Sub
'====================================================================
' ShowPage Create a pager bar
' There's a homepage, a previous page, the next page, the last, and the digital navigation
'====================================================================
Public Sub ShowPage ()
Dim str_tmp
Int_totalrecord=xd_rs. RecordCount
If int_totalrecord<=0 Then
Str_error=str_error & "Total record number is zero, please enter data"
Call ShowError ()
End If
If int_totalrecord<pagesize Then
Int_totalpage=1
Else
Int_totalpage=xd_rs. PageCount
' If int_totalrecord mod PageSize =0 Then
' Int_totalpage = CLng (int_totalrecord/xd_pagesize *-1) *-1
' Else
' Int_totalpage = CLng (int_totalrecord/xd_pagesize *-1) *-1+1
' End If
End If
If Int_curpage>int_totalpage Then
Int_curpage=int_totalpage
End If
'===============================================================================
' Display paging information, each module needs to change the location
'===============================================================================
Response.Write "<table border=0 width=" &XD_Width& "><tr><td align=" &XD_Align& ">"
Str_tmp=showfirstprv
Response.Write str_tmp
Str_tmp=shownumbtn
Response.Write str_tmp
Str_tmp=shownextlast
Response.Write str_tmp
Str_tmp=showpageinfo
Response.Write str_tmp
Response.Write "</td></tr></table>"
End Sub
'====================================================================
' SHOWFIRSTPRV display homepage, previous page
'====================================================================
Private Function SHOWFIRSTPRV ()
Dim Str_tmp,int_prvpage
If int_curpage=1 Then
str_tmp=btn_first& "" &btn_prev
Else
Int_prvpage=int_curpage-1
str_tmp= "<a href=" &geturl& "1>" &Btn_First& "</a><a href=" &geturl & Int_ Prvpage & ">" & btn_prev& "</a>"
End If
Showfirstprv=str_tmp
End Function
'====================================================================
' Shownextlast next page, last
'====================================================================
Private Function Shownextlast ()
Dim Str_tmp,int_nextpage
If Int_curpage>=int_totalpage Then
Str_tmp=btn_next & "" & Btn_last
Else
Int_nextpage=int_curpage+1
str_tmp= "<a href=" & Geturl & Int_nextpage & ">" &Btn_Next& "</a><a href=" &geturl & Int_totalpage & ">" & btn_last& "</a>"
End If
Shownextlast=str_tmp
End Function
'====================================================================
' SHOWNUMBTN Digital Navigation
'====================================================================
Private Function shownumbtn ()
Dim i,str_tmp
For I=1 to Int_totalpage
Str_tmp=str_tmp & "<a href=" & Geturl & I & ">[" &i& "]</a>"
Next
Shownumbtn=str_tmp
End Function
'====================================================================
' Showpageinfo Paging information
' It is also required to modify its own
'
'====================================================================
Private Function Showpageinfo ()
Dim str_tmp
str_tmp= "page: &int_curpage&"/"&int_totalpage&" page Total "&int_totalrecord&" record &xd_pagesize & "article/every page"
Showpageinfo=str_tmp
End Function
'==================================================================
' GetURL get the current URL
' More depending on the URL parameter, get different results
'==================================================================
Private Function GetURL ()
Dim Strurl,str_url,i,j,search_str,result_url
Search_str= "Page="
Strurl=request.servervariables ("URL")
Strurl=split (strURL, "/")
I=ubound (strurl,1)
' Response.Write I
' Response.End
Str_url=strurl (i) ' Get the current page filename
Str_params=request.servervariables ("Query_string")
If str_params= "" Then
Result_url=str_url & "Page="
Else
If InStrRev (str_params,search_str) =0 Then
Result_url=str_url & "?" & Str_params & "&page="
Else
J=instrrev (STR_PARAMS,SEARCH_STR)-2
If J=-1 Then
Result_url=str_url & "Page="
Else
Str_params=left (STR_PARAMS,J)
Result_url=str_url & "?" & Str_params & "&page="
End If
End If
End If
Geturl=result_url
End Function
Private Sub ShowError ()
If str_error <> "" Then
Response.Write ("<font color=" "#FF0000" "><b>" & Sw_error & "</font>")
Response.End
End If
End Sub
End Class
%>

Related Article

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.