Common Data Paging classes

Source: Internet
Author: User
Tags sort table name
Pagination | General data paging class, it is easier to write pagination later to display the data. Call this class directly, and then execute to get all the data for the current page.
The work done by this class is to get only the data for the current page, and the total number of pages and total records, and so on.

ASP code:

<%
'/***************************** pagination Display class **************************
'/* Author: wah-yu
'/* Date: November 18, 2004
'/* Function: Get a page of data and return to the external
'/* Description Example:
'/* Dim mypage=new Pageclass
'/* mypage.conn=conn ' Sets the Connection object
'/* mypage.pagesize=20 ' sets how many data is displayed on a page (default is 10)
'/* mypage.curpage=2 ' sets the current page number to display
'/*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'/* mypage.tablename= ' member ' sets the table name
'/* mypage.fields= ' id,membername,memberpass ' Set display field List
'/* mypage.condition= ' id>100 ' Set query criteria
'/* mypage.orderby= ID DESC ' Set sort criteria (be sure to set this property)
'/* Set Pagers=mypage.execute ' returns the data (Recordset object) for the current 2nd page and returns Nothing if an error occurs
'/*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
The definition of '/* ' can also be used in the following ways: Executeby (table name, field list, query criteria, sort criteria)
'/* Set Pagers=mypage.executeby ("member", "Id,membername,memberpass", "id>100", "ID DESC")
'/*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'/* pagecount=mypage.pagecount ' returns the total number of page numbers
'/* recordcount=mypage.recordcount ' returns the total number of records
'/* nextpage=mypage.nextpage ' returns the page number of the next page
'/* prepage=mypage.prepage ' returns the page number of the previous page
'/*****************************************************************
Class Pageclass
Private Connection ' Connect the external Connection object of the database
Private Rs
Private List_fields
Private table_name
Private Query_where
Private orderby_sql ' field sort statement section
Private Page_count ' Returns the total number of record pages for the current query
Private page_size ' Sets the record of how many pages a page displays
Private Cur_page ' Set the current page number
Private Record_count ' Returns the total number of records in the current query
'/**************** set Connection object ****************************
Public Property Let Conn (ByRef objconn)
Set Connection=objconn
End Property
Public Property Get Conn ()
Set conn=connection
End Property
'/****************end******************************************

'/**************** set query SQL statement *******************************
' Query display field
Public Property Let Fields (ByVal Value)
List_fields=value
End Property
Public Property Get Fields ()
Fields=list_fields
End Property
' Query table name
Public Property Let TableName (ByVal Value)
Table_name=value
End Property
Public Property Get TableName ()
Tablename=table_name
End Property
' Query criteria
Public Property Let Condition (ByVal Value)
Query_where=value
End Property
Public Property Get Condition ()
Condition=query_where
End Property
' ***************** Sort part ********************************************
' Value ' does not have to be written in order by. such as: [Object]. orderby= "ID desc,posttime Asc"
Public Property Let-by (ByVal Value)
Orderby_sql=value
End Property
Public Property Get By ()
Orderby=orderby_sql
End Property
'/****************end******************************************

'/**************** returns the total number of pages for the current query result ***********************
Public Property Get PageCount ()
Pagecount=page_count
End Property
Public Property Get RecordCount ()
Recordcount=record_count
End Property
Public Property Get NextPage ()
If Cur_page<page_count Then
Nextpage=cur_page+1
Else
Nextpage=page_count
End If
End Property
Public Property Get Prepage ()
If cur_page>1 Then
Prepage=cur_page-1
Else
Prepage=cur_page
End If
End Property
'/****************end******************************************

'/**************** set the number of records displayed on a page ***************************
Public Property Let PageSize (ByVal Value)
If not IsNumeric (Value) Or value= "" Then
value=10
Else
Value=cint (Value)
End If
If value<1 Then value=10
Page_size=value
End Property
Public Property Get PageSize ()
Pagesize=page_size
End Property
' Set the current number of pages **************************
Public Property Let Page (ByVal Value)
If not IsNumeric (Value) Or value= "" Then
Value=1
Else
VALUE=CLNG (Value)
End If
If value<1 Then value=1
Cur_page=value
End Property



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.