From the beginning of learning to using ASP to now, I have written many programs. The most troublesome thing is writing data paging. Each time, it is due to the difference of several variable names or several parameters. Therefore, it is necessary to write a lengthy and complicated paging code every time. The long code makes the readability of the program worse and it is easy to travel on business. I can't find any mistakes after debugging for a long time, so I slowly started to use some paging functions or paging classes provided on the Internet. It is indeed a lot of trouble-free, but the usual method of functions and classes is to encapsulate the data display part. Every time, in order to achieve the desired effect, the function or class itself must be changed, so it is not very convenient to use. The pages written by yourself are already complicated enough, let alone other people's.
So I wrote a paged class by myself while I had time yesterday, and felt good about myself (don’t smash me with an egg). I will share my experience with you here (I can’t talk about experience, let’s think about it). I don’t want to talk about the principle of pagination here anymore. Anyway, everyone understands it, and I won’t know if I want to talk in depth. hehe.
1. The goal of creating a paging class
Before writing, I thought about what kind of class I wanted to write. When I recalled the past when writing paging, the most annoying thing was what complicated paging code I had to write every time. The biggest worry was that each time was the difference between just a few variable names. So the first thing to achieve is to encapsulate this, the second is to encapsulate the navigation bar of the pagination. The third is to encapsulate the data display part by not being used to. This is not convenient to program, and for users who have different display effects every time, it is more troublesome than writing paging by themselves. So my goal is to make some simple encapsulation of RecordSet.
2. Creation process
So the first property I wrote is to return a processed RecordSe
PublicPropertyGetGetRs()SetXD_Rs=Server.createobject("adodb.recordset")
XD_Rs.PageSize=PageSize
XD_Rs.OpenXD_SQL,XD_Conn,1,1
Ifnot(XD_Rs.eofandXD_RS.BOF)Then
Ifint_curpage>XD_RS.PageCountThen
int_curpage=XD_RS.PageCount
EndIf
XD_Rs.AbsolutePage=int_curpage
EndIf