CS分页类V1.2
<%'转发时请保留此声明信息,这段声明不并会影响你的速度!
'******************* CS分页类V1.2 ************************************
'作者:ColorSunny
'日 期:2006-02-26
'网站:http://www.900wan.com
'电子邮件:keechi@163.com
'版权声明:版权所有,源代码公开,各种用途均可免费使用,但是修改后必须把修改后的文件
'发送一份给作者,并且保留作者此版权信息
'类属性说明:
'strSql SQL语句 必选项
'PageSize 每页条数 可选 默认为10
'strUrl 联接地址 可选 默认为 "?page=" 可写为如 "Article_List.asp?Class=222&page="
'strUnit 统计信息 可选 默认为 "共$A$条记录,$B$条记录/页,当前第$C$页" 其中$A$ $B$ $C$ 将被替换成数字
'strFst 首页 可选 默认为 "首页"
'strPre 上一页 可选 默认为 "上一页"
'strNxt 下一页 可选 默认为 "下一页"
'strLst 尾页 可选 默认为 "尾页"
'strGoto 转到 可选 默认为 "转到"
'connection 数据库链接 可选 默认为 conn
'**********************************************************************
'应用实例
'set dp1 = new CS_DividePage
'dp1.strSql = "select * from Article"
'Set rs = dp1.Recordset
'For i = 1 To dp1.Pagesize
' If rs.Eof Then Exit For
' Response.Write rs("artTitle") & "<BR>"
' rs.Movenext
'Next
'dp1.ShowPage()
'set dp1 = nothing
'**********************************************************************
Class CS_DividePage
Dim Page, PageCount, RsCount, z
Dim PageSize_CS, strUrl_CS, strUnit_CS, strSql_CS, conn_CS '需要得到的参数
Dim strFst_CS, strPre_CS, strNxt_CS, strLst_CS, strGoto_CS '需要得到的参数
Public Property Let strSql(ParamA) 'Sql字符串
strSql_CS=ParamA
End Property
Public Property Let PageSize(ParamB) '每页大小
PageSize_CS=ParamB
End Property
Public Property Let strUrl(ParamC) '地址
strUrl_CS=ParamC
End Property
Public Property Let strUnit(ParamD) '单位
strUnit_CS=ParamD
End Property
Public Property Let strFst(ParamE) '首页
strFst_CS=ParamE
End Property
Public Property Let strPre(ParamF) '上一页
strPre_CS=ParamF
End Property
Public Property Let strNxt(ParamG) '下一页
strNxt_CS=ParamG
End Property
Public Property Let strLst(ParamH) '尾页
strLst_CS=ParamH
End Property
Public Property Let strGoto(ParamI) '转向
strGoto_CS=ParamI
End Property
Public Property Let connection(ParamJ) '数据库链接
Set conn_CS=ParamJ
End Property
Private Sub Class_Initialize '类初始化
Page = Request("page")
If Page = "" Then Page = 1 Else If Not IsNumeric(Page) Then Page = 1
Page = CInt(Page)
If Page < 1 Then Page = 1
PageSize_CS = 10
strUrl_CS = "?page="
strUnit_CS = "共$A$条记录,$B$条记录/页,当前第$C$页"
strFst_CS = "首页"
strPre_CS = "上一页"
strNxt_CS = "下一页"
strLst_CS = "尾页"
strGoto_CS = "转到"
If IsObject(conn) Then Set conn_CS = conn
End Sub
Private Sub Class_Terminate '类终止
Recordset.Close
'Set Recordset = Nothing
End Sub
Public Property Get PageSize
PageSize = PageSize_CS
End Property
Public Property Get Recordset '打开记录并分页
Set Recordset = Server.CreateObject("Adodb.RecordSet")
Recordset.open strSql_CS, conn_CS, 1, 1
Recordset.PageSize = PageSize_CS
PageCount = Recordset.PageCount
RsCount = Recordset.RecordCount
If Page > PageCount Then Page = PageCount
If Not Recordset.Eof Then Recordset.AbsolutePage = Page
End Property
Public Sub ShowPage()
If Page > 1 Then
Response.Write "<a href=""" & strUrl_CS & "1"">" & strFst_CS & "</a> "
Response.Write "<a href=""" & strUrl_CS & Page-1 & """>" & strPre_CS & "</a> "
Else
Response.Write strFst_CS & " " & strPre_CS
End If
Response.Write " (" & Replace(Replace(Replace(strUnit_CS, "$A$", RsCount), "$B$", PageSize_CS),"$C$" , Page & "/" & PageCount) & ") "
If PageCount > Page Then
Response.Write "<a href=""" & strUrl_CS & Page+1 & """>" & strNxt_CS & "</a> "
Response.Write "<a href=""" & strUrl_CS & PageCount & """>" & strLst_CS & "</a>"
Else
Response.Write strNxt_CS & " " & strLst_CS
End If
Response.Write VbCrlf & " " & strGoto_CS & " <select name=""GotoPage_ColorSunny"" onchange=""window.location.href='"
Response.Write strUrl_CS & "'+GotoPage_ColorSunny.value"">"
For z = 1 To PageCount
Response.Write "<option value=" & z
If z = Page Then Response.Write " selected "
Response.Write ">" & z & "</option>" & VbCrlf
Next
Response.Write "</select>"
End Sub
End class
%>
[此贴子已经被作者于2006-3-23 16:10:41编辑过]