ASP Classic Page-type

Source: Internet
Author: User
=====================================================================
' Xdownpage ASP version
' Version 1.00
' Code by zykj2000
' Email:zykj_2000@163.net
' bbs:http://bbs.513soft.net/
' This program can be free to use, modify, I hope my program can bring convenience to your work
' But please keep the above interest
'
' Program features
' This program is mainly to the data pagination part of the encapsulation, and the data display part completely by the user customization,
' Support URL multiple parameters
'
' Use instructions
' Program parameter description
' 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
'
' Include file
'
' 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= "9"    "Define first page button display style
Const btn_prev=" 3 "  " Define previous page button display style
Const btn_next= "4    Define next page button display style
Const btn_last=:    Define last page button display style
Const xd_align= "center"        ' Define pagination information alignment
Const xd_width= ' 100% '       ' Define paging information box size
Const xd_ height=
Class xdownpage
Private xd_pagecount,xd_conn,xd_rs,xd_sql,xd_pagesize,str_errors,int_curpage, Str_url,int_totalpage,int_totalrecord


' =================================================================
' pagesize  properties
' Sets the paging size for each page The
' =================================================================
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 PageSize
 if xd_pagesize= "" or (Not (IsNumeric (xd_pagesize)) Then
   PAGESIZE=10    &NBSP
 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 int_totalpage=1
Else
If int_totalrecord mod PageSize =0 Then
Int_totalpage = Int (int_totalrecord/xd_pagesize *-1) *-1
Else
Int_totalpage = Int ((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 "

"
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 '
"
Showgoto
Response.Write "
"

End Sub

' ====================================================================
' showfirstprv   display first, 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= "" &Btn_First& " " & btn_prev& ""
 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= "" &Btn_Next& "& btn_last&" "
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 & ' [&i&] '
' Next
' Shownumbtn=str_tmp
'
' End Function
'====================================================================
' Shownumbtn revised digital navigation
'
'====================================================================
Function shownumbtn ()
Dim I,str_tmp,end_page,start_page
If Int_curpage>4 Then
If Int_curpage+2 start_page=int_curpage-2
End_page=int_curpage+2
Else
Start_page=int_totalpage-4
End_page=int_totalpage
End If
Else
Start_page=1
If Int_totalpage>5 Then
End_page=5
Else
End_page=int_totalpage
End If
End If
For I=start_page to End_page
Str_tmp=str_tmp & "[" &i&] "
Next
Shownumbtn=str_tmp
End Function

'====================================================================
' Showgoto page jump
'
'
'====================================================================
Private Function Showgoto ()
Dim M_item
'========================================================
' writes the returned URL parameter to the hidden field one by one to continue passing with the argument
'========================================================
For each m_item in Request.QueryString
If InStr ("page", M_item) =0 Then ' Removes the value of ' page ' from the argument
Response.Write ""
End If
Next
'========================================================
Response.Write "Go to page:"
Response.Write "Page"
End Function


' ====================================================================
' showpageinfo   paging information
' more requested to modify
'
' ====================================================================
Private Function Showpageinfo ()
 dim str_tmp
 str_tmp=  [page: "&int_curpage&"/"&int_totalpage & "Page] [total &int_totalrecord&] [[&XD_PageSize&] Strip/page]"
 showpageinfo=str_tmp
End Function

' ====================================================================
' modifies the function that gets the current URL parameter
' codeing by Redsun
' ====================================================================
Private Function GetUrl ()
 dim scriptaddress, M_itemurl, m_item
 scriptaddress = CStr (Request.ServerVariables ("SCRIPT_NAME")) & "?" ' Get the current address
 if (request.querystring <> "") Then
  m_itemurl = ""
  for each M_item In Request.QueryString
   if InStr ("page", M_item) =0 Then
    m_itemurl = M _itemurl & m_item & "=" & Server.URLEncode (Request.QueryString ("" &M_Item& ")) &" & "
   end If
  next
  scriptaddress = scriptaddress & M_ItemUrl ' Gets the address with the parameter
 end If
 geturl = scriptaddress & "page="
End Function

'====================================================================
' Set the Terminate event.
'====================================================================
Private Sub Class_Terminate
Xd_rs.close
Set xd_rs=nothing
End Sub
'====================================================================
' ShowError error hint
'====================================================================
Private Sub ShowError ()
If str_error <> "" Then
Response.Write ("
"& Sw_error &" ")
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.