<%
'================================================ ==============
'Xdownpage ASP version
'Version 1.00
'Code by zykj2000
'Email: zykj_2000@163.net
'Bbs: http://bbs.513soft.net
'The program can be used and modified for free. I hope my program will be convenient for your work.
'But keep the above information
'==========================================
'Display pagination bar style R. Koo modification like bleaidea
'==========================================
'
'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 property description
'Showpage displays the navigation bar by page, which has unique attributes.
'
'Example:
'Contains files
'Set mypage = new xdownpage' create object
'Mypage. getconn = conn' to get the database connection
'Mypage. getsql = "select * From productinfo order by id asc"
'Mypage. pagesize = 5' sets the number of records on each page to 5
'Set rs = mypage. getrs () 'returns recordset
'For I = 1 to mypage. pagesize' the following operations are the same as operations on a common recordset object.
'If not Rs. EOF then' is marked to prevent overflow on the last page.
'Response. Write & RS (0) & "" 'Here you can customize the display mode.
'Rs. movenext
'Else
'Exit
'End if
'Next
'Response. Write mypage. showpage displays page information after set rs = mypage. getrs ()
'================================================ ====================
Class xdownpage
Private xd_pagecount, xd_conn, xd_rs, xd_ SQL, xd_pagesize, str_errors, int_curpage, str_url, int_totalpage, int_totalrecord, str_error, sw_error
'================================================ =
'Pagesize Property
'Set the page size for each page
'================================================ =
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
'====================================
'Display pagination bar style R. Koo modification like bleaidea
'==================================
Public Function page ()
Dim str_tmp, str_fisrt, str_prev, str_next, str_last, str_info, str_select, I
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> 0 then 'int _ totalpage = 1
If int_totalrecord mod pagesize = 0 then
Int_totalpage = clng (int_totalrecord/xd_pagesize)
Else
Int_totalpage = clng (int_totalrecord/xd_pagesize) + 1
End if
End if
If int_curpage> int_totalpage then
Int_curpage = int_totalpage
End if
If int_curpage = 1 then
Str_fisrt = "Homepage"
Str_prev = "front page"
Else
Str_fisrt = "<a href =" & geturl & "1" & ""> homepage </a>"
Str_prev = "<a href =" & geturl & int_curpage-1 & ""> previous page </a>"
End if
If int_curpage> = int_totalpage then
Str_next = ""
Str_last = "last page"
Else
Str_next = "<a href =" "& geturl & int_curpage + 1 &" "> next page </a>"
Str_last = "<a href =" "& geturl & int_totalpage &" "> last page </a>"
End if
Str_select = "<Select style =" "Font: 8pt;" "onchange =" "If (this. Options [This. selectedindex]. value! = '') {Location = This. Options [This. selectedindex]. value;}" ">"
For I = 1 to int_totalpage
Str_select = str_select & "<option value =" "& geturl & I &""""
If int_curpage = I then str_select = str_select & "selected" 'str _ TMP = str_tmp & "[" & I & "]" else str_tmp = str_tmp & "<a href = "" "& geturl & I &" "> [" & I & "] </a>"
Str_select = str_select & ">" & I & "</option>"
Next
Str_select = str_select & "</SELECT>"
Str_info = "Page times: <B>" & int_curpage & "</B>/<B>" & int_totalpage & "</B> & nbsp; Page & nbsp; <B> "& xd_pagesize &" </B> items/Page & nbsp; go to "& str_select &" Page & nbsp; total <B> "& int_totalrecord &" </B> records"
Page = str_fisrt & "& nbsp;" & str_prev & "& nbsp;" & str_next & "& nbsp;" & str_last & "<br>" & str_info
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, str_params
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 = 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
End if
End if
Geturl = result_url
End Function
'================================================ ====
'Set the terminate event.
'================================================ ====
Private sub class_terminate
Xd_rs.close
Set xd_rs = nothing
End sub
'================================================ ====
'Showerror error message
'================================================ ====
Private sub showerror ()
If str_error <> "" then
Response. write ("<Div align =" "center" "> error <br> <a href ="> return </a> </div>")
Response. End
End if
End sub
End Class
%>