Xdownpage ASP version paging class

Source: Internet
Author: User
Tags servervariables

<%
'================================================ ======================================
'Xdownpage ASP version
'Version 1.00
'Code by zykj2000
'Email: zykj_2000@163.net
'Bbs: http://bbs.513soft.net
'Ben Program It can be used and modified for free. I hope my program will be convenient for your work.
'But keep the above information
'
'Program features
'The program encapsulates the data paging part, and the data display part is completely customized by the user,
'Multiple URL parameters are supported.
'
'Instructions for use
'Program parameter description
'Papgesize defines the number of records per page.
'Getrs returns the paged recordset. This attribute is read-only.
'Getconn get database connection
'Getsql: query statement obtained
'Program Method description
'Showpage display pagination navigation bar, the only public Method
'
'================================================ ======================================

Const btn_first = "<font face =" "webdings"> 9 </font> "'defines the display style of the button on the first page.
Const btn_prev = "<font face =" "webdings"> 3 </font> "'defines the display style of buttons on the previous page.
Const btn_next = "<font face =" "webdings"> 4 </font> "'defines the display style of the next page button
Const btn_last = "<font face =" "webdings" >:</font> "'defines the button display style on the last page.
Const xd_align = "center" 'defines the page information alignment Mode
Const xd_width = "100%" 'defines the size of the page information box

Class xdownpage
Private xd_pagecount, xd_conn, xd_rs, xd_ SQL, xd_pagesize, str_errors, int_curpage, str_url, int_totalpage, int_totalrecord, xd_surl

'============================================ =============================< br> 'pagesize attribute
'settings page size of each page
'============================== =======================================================< br> Public Property let pagesize (int_pagesize)
If isnumeric (int_pagesize) Then
xd_pagesize = clng (int_pagesize)
else
str_error = str_error & "The pagesize parameter is 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 attributes
'Return the record set after pagination
'================================================ ======================================
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 database connection
'
'================================================ ======================================
Public property let getconn (obj_conn)
Set xd_conn = obj_conn
End Property

'================================================ ======================================
'Getsql: query statement obtained
'
'================================================ ======================================
Public property let getsql (str_ SQL)
Xd_ SQL = str_ SQL
End Property

'================================================ ======================================
'Class _ initialize class initialization
'Initialize the value of the current page
'
'================================================ ======================================
Private sub class_initialize
'====================================
'Set the token value for some parameters
'====================================
Xd_pagesize = 10' set the default page size to 10.
'====================================
'Get the current value
'====================================
If request ("page") = "" then
Int_curpage = 1
Elseif not (isnumeric (Request ("page") then
Int_curpage = 1
Elseif CINT (TRIM (Request ("page") <1 then
Int_curpage = 1
Else
Int_curpage = CINT (TRIM (Request ("page ")))
End if

End sub

'================================================ ==================================
'Showpage creates a paging navigation bar
'The Home Page, Previous Page, next page, last page, and digital navigation
'
'================================================ ==================================
Public sub showpage ()
Dim str_tmp
Xd_surl = geturl ()
Int_totalrecord = xd_rs.recordcount
If int_totalrecord <= 0 then
Str_error = str_error & "the total number of records is zero. Please input data"
Call showerror ()
End if
If int_totalrecord = "" then
Int_totalpage = 1
Else
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 can change the explicit position as required.
'================================================ ======================================
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 ""
End sub

'============================================ =====================================< br> 'showfirstprv display the home page, previous Page
'======================== ========================================================== ==< br> 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

'============================================ ===================================< br> 'shownextlast next page and last page
'======================== ==========================================================
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 = "" & xd_surl & CSTR (int_nextpage) & ">" & btn_next & " " & btn_last & ""
end if
shownextlast = str_tmp
end function

'============================================ ===================================< br> 'shownumbtn digital navigation
'
' ======================== =====================================================< BR> private function shownumbtn ()
dim I, str_tmp
for I = 1 to int_totalpage
str_tmp = str_tmp & "[" & I & "]"
next
shownumbtn = str_tmp
end function

'================================================ ==================================
'Showpageinfo page information
'Modify as required
'
'================================================ ==================================
Private function showpageinfo ()
Dim str_tmp
Str_tmp = "Page times:" & int_curpage & "/" & int_totalpage & "Page total" & int_totalrecord & "record" & xd_pagesize & "/page"
Showpageinfo = str_tmp
End Function
'================================================ ======================================
'Geturl: Get the current URL.
'Obtain different results based on different URL parameters
'
'================================================ ======================================
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)
Str_url = strurl (I) 'to get the file name of the current page

str_params = trim (request. servervariables ("QUERY_STRING")
If str_params = "" Then
result_url = str_url &"? Page = "
else
If limit Rev (str_params, search_str) = 0 then
result_url = str_url &"? "& Str_params &" & page = "
else
J = Limit Rev (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
geturl = result_url
end function

'============================================ =====================================< br> 'set the terminate event.
'================================ ================================================================< br> private sub class_terminate
xd_rs.close
set xd_rs = nothing
end sub
'================ ========================================================== ===========< br> 'showerror error message
'========== ========================================================== ==========================< br> private sub showerror ()
If str_error <> "" Then
response. write ("" & str_error & "")
response. end
end if
end sub
end class

'Set conn = server. Createobject ("ADODB. Connection ")
'Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("/data/5iduohai. mdb ")
'
''' ############# Class call example #################
''Create object
'Set mypage = new xdownpage
''Get database connection
'Mypage. getconn = Conn
''SQL statement
'Mypage. getsql = "select * from [dh_company] Order by id asc"
''Set the number of records on each page to 5
'Mypage. pagesize = 5
''Return recordset
'Set rs = mypage. getrs ()
'Display paging information. This method can be called anywhere after set rs = mypage. getrs (). It can be called multiple times.

'
''Display data
'Response. Write ("<br/> ")
'For I = 1 to mypage. pagesize
''Here you can customize the display mode.
'If not Rs. EOF then
'Response. Write RS (0) & "<br/>"
'Rs. movenext
'Else
'Exit
'End if
'Next
'Mypage. showpage ()
%>

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.