Create an ASP universal paging class
Wave
From the beginning of learning to use ASP, there are still many programs, the most headache is written data paging, each time due to several variable names or several parameters, which requires which paragraph every time The lengthy and complicated paging code, the code is long, which makes the program's readability, easy to travel, the debug is not missing for a long time, so slowly I start using some online supplied paging functions or panesses. It is indeed a lot of things, but the usual functions and classes are also encapsulated on the data display section. Every time I want to change the function or class itself, it is not convenient to use it. I have been complicated enough to write the paging it yourself. Don't say others.
So, I have time I wrote a paging class yesterday, I feel good, I don't want to use eggs. I share my experience with you (talk about experience, thinking about it). Here I don't want to say the principle of paging, anyway, everyone knows, I have to talk about it in depth, I will not. Ha ha.
First, create the goal of the page class
Before writing, I thought about how to write a class. When I recall, when I have written the paging process, I am most annoying that I have to write which complex paging code is written every time. The biggest trouble every time. It is only a few variable names. So the first thing to implement is to put this package, the second is to encapsulate the navigation bar of the paging, the third, not used to encapsulate the data display parts, which is not convenient to program, For those who have different display effects every time, it is more troublesome than yourself. So my purpose is some simple packages for RecordSet.
Second, create a process
So the first attribute I wrote is to return a processed Recordset
Public property Get 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.PAGECUNT THEN
INT_CURPAGE = XD_RS.PAGECOUNT
END IF
XD_rs.absolute = int_curbage
END IF
Set getrs = XD_RS
End Property
The role of this attribute is more than the current surface of the specified Recordset and the first record of the pointer points to the current page. This should be the core of the entire class, of course, some of the parameters are obtained by other properties. So here is the basic parameters of this class to be introduced here.
'=============================================
'GetConn gets database connections
'
'============================================= ======= plic printy Let getConn (Obj_conn)
SET XD_CONN = Obj_conn
End Property
'=============================================
'GetSQL gets query statements
'
'===============================================
Public property let getsql (STR_SQL)
XD_SQL = STR_SQL
End Property
'===============================================
'PageSize properties
'Set the page 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 is incorrect"
Showerror ()
END IF
End Property
Public property Get Pagesize
IF xd_pagesize = "" or (not (isnumeric (xd_pagesize)).
PageSize = 10
Elsepagesize = xd_pagesize
END IF
End Property
The above is the need to specify the parameters in the process of using the class. I used to judge every incoming parameter when writing attributes. It is the robust of the class, but I wanted to go later. This is not necessary to talk to the ASP, it is not enough to speed up the point speed. As for why, I think you will find it during use, it is better not to add. This is also after I have been thinking, I only retain some necessary verification.
There is also a parameter is the current page acquisition. In the program I use int_curpage to identify, this is not good in the creation process of the class.
Private sub coplass_initialize
'==========================
'Set some parameters 黙 recognition
'==========================
XD_PageSize = 10 'Setting the default value of 10
'==========================
'Get the front value
'==========================
If Request ("Page") = "" "
INT_CURPAGE = 1
Elseif Not (ISNUMERIC (Request ("Page")))
INT_CURPAGE = 1
Elseif Cint (TRIM (Request ("Page"))) <1 THEN
INT_CURPAGE = 1
Else
INT_CURPAGE = CINT (TRIM (Request ("Page"))))
END IF
End Sub
The functionality of this class is basically all, as long as the URL of the page is called, add Page = n, it will display the contents of the nth page, so the next thing to do is to create a data navigation. The bar, I design it as a similar surface
9 3 [1] [2] [3] [4] [5] [6] [7] [8] 4: Page: 1/8 page Total 51 records 7 / per page
In the page, the showpage can be called in any location after GETRS, or call multiple times.
Public Sub ShowPage () Dim str_tmp int_totalRecord = XD_RS.RecordCount If int_totalRecord <= 0 Then str_error = str_error & "the total number of records is zero, the data enter" Call ShowError () End If If int_totalRecord