ASP分页代码,已经写成类了,值得参考

发表于:2007-06-30来源:作者:点击数: 标签:
ASP通用分页类 一、类的属性、方法 这是一个ASP通用分页类。你可以用它方便的给记录集分页,当然在网上有许多的分页类和分页函数。本分页主要有Conn、 SQL 、URL、FieldList、PageSize、Template、Init、Show、Close等属性和方法。 1.Conn属性 :用来获取一个
ASP通用分页类


一、类的属性、方法
  这是一个ASP通用分页类。你可以用它方便的给记录集分页,当然在网上有许多的分页类和分页函数。本分页主要有Conn、SQL、URL、FieldList、PageSize、Template、Init、Show、Close等属性和方法。
  1.Conn属性    :用来获取一个已创建的Connection对象。
  2.SQL属性      :根据传入的SQL语句,自动创建RecordSet对象
  3.PageSize属性   :设置第页的记录条数
  4.FieldList属性    :如果需要显示库中的数据,一定要设置此属性。它是用来获取需要显示的正确的字段名。
  5.URL属性     :设置分页条中链接的文件地址。
  6.Template属性   :设置分页文件的模版。
  7.Init过程     :分页类初始化数据。
  8.Show过程   :显示数据。
  9.Close过程    :分页类结束

全部代码由此下载

二、类的源代码(inc_clsPage.asp)

<%
‘’/************************************************
‘’* *
‘’* Name : Asp pagnation class *
‘’* Author : cjj *
‘’* Version : V2.8 *
‘’* Time : 2004-01-16 *
‘’* Comefrom: http://www.blueidea.com/ *
‘’* HomePage: None (Maybe Soon) *
‘’* Notice : You can use and modify it freely, *
‘’* BUT PLEASE HOLD THIS ITEM. *
‘’* If you modify it that i hope you *
‘’* can send a mail for me. *
‘’* *
‘’************************************************/

‘’#########声明变量#########

‘’定义链接的显示类型
Const SW_intShowChinese = 0 ‘’汉字,如"上一页、下一页"
Const SW_intShowEnglish = 1 ‘’英文,如"Back、Next"
Const SW_intShowCharacter = 2 ‘’特殊字符
‘’定义数据的显示类型
Const SW_intHorizontalView = 0 ‘’横排
Const SW_intVerticalView = 1 ‘’竖排
‘’线的显示类型
Const SW_intShowBigBorder = 2 ‘’粗线
Const SW_intShowSmallBorder = 1 ‘’细线
Const SW_intShowNoBorder = 0 ‘’无线

‘’标题栏线的显示类型
Const SW_intTleSmallBorder = 1 ‘’细线
Const SW_intTleNoBorder = 0 ‘’无线

‘’显示分页信息的位置
Const SW_intPageInNone = 0 ‘’不显示分页条
Const SW_intPageInTop = 1 ‘’在顶部显示
Const SW_intPageInBottom = 2 ‘’在底部显示
Const SW_intPageInAll = 3 ‘’在顶、底部显示

‘’显示的页数的数字个数
Const SW_intShowPages = 10

‘’SWPage Class
Private SW_blnIsHaveRS,SW_strFields,SW_blnInConn,SW_intShowPagePos,SW_strShowWidth
‘’#########初始化变量##########
SW_blnIsHaveRS = false ‘’设置记录集获取标志为Fasle,就是无记录集状态
SW_strShowWidth = "90%" ‘’默认的显示宽度为90%
SW_strFields = ""
SW_blnInConn = true ‘’由内部创建Connection,如果设为False则由外部创建
SW_intShowPagePos = SW_intPageInAll


‘’*****************************************
‘’ 类型: 类
‘’ 目的: 给记录集分页
‘’*****************************************
Class SWPage
‘’声明类私有变量
Private SW_objRS,SW_objConn

Private SW_strSQL,SW_strURL,SW_strError,SW_strFormAction,SW_strHeadJS,SW_strFootJS

Private SW_intPageSize,SW_intTleBDType,SW_intShowPageType,SW_intShowType
Private SW_lngTotalPage,SW_lngTotalRecord,SW_lngPageNo
Private SW_aryFldName,SW_aryFldNote,SW_aryFldWidth,SW_aryFldAlign,SW_aryFldLink
Private SW_blnInit,SW_blnOpenRS,SW_blnConn,SW_blnPageSize,SW_blnFieldList,SW_blnGetURL,SW_blnShowType,SW_blnShowPageType,SW_blnTemplate

‘’*****************************************
‘’ 类型: 属性
‘’ 目的: 根据获取的信息,创建数据库连接
‘’ 输入: a_strConn:数据类型字符串
‘’ 返回: 无
‘’*****************************************
Public Property Let Conn(a_strConn)
Dim strError
SW_blnConn = false
Set SW_objConn = CreateObject("Adodb.Connection")
On Error Resume Next
SW_objConn.Open a_strConn
If Err.Number <> 0 Then strError = strError & "<br>创建Connection对象失败"
On Error Goto 0

If Trim(strError)="" Then
SW_blnConn = true
Else
SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">Conn属性:</font></td></tr>" & vbcrlf
SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
End If
End Property

‘’*****************************************
‘’ 类型: 属性
‘’ 目的: 设定或显示SQL语句。
‘’ 输入: a_strSQL: SQL语句。
‘’ 返回: SQL语句。
‘’*****************************************
Public Property Let SQL(a_strSQL)
Dim strError

SW_blnOpenRS = false
SW_strSQL = a_strSQL

‘’创建RecordSet对象
Set SW_objRS = CreateObject("adodb.RecordSet")
On Error Resume Next
SW_objRS.Open SW_strSQL,SW_objConn,1,1
If Err.Number <> 0 Then strError = "<br>记录集打开失败"
On Error Goto 0

If Trim(strError)="" Then
SW_blnOpenRS = true
Else
SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">SQL属性:</font></td></tr>" & vbcrlf
SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
End If
End Property


‘’*****************************************
‘’ 类型: 属性
‘’ 目的: 设置需要显示的数据的字段名
‘’ 输入: a_strFldName:字段名字符串,多个字段之间以逗号分隔
‘’ 返回: 无
‘’*****************************************
Public Property Let FieldList(a_strFldName)
Dim strError

SW_blnFieldList = false
If Trim(a_strFldName) <> "" Then
SW_aryFldName = Split(LCase(a_strFldName),",")
Else
strError = strError & "<br>你必须设置需要显示的字段名,否则无法显示数据"
End If
If Trim(strError)="" Then
SW_blnFieldList = true
Else
SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">FieldList属性:</font></td></tr>" & vbcrlf
SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
End If
End Property

‘’*****************************************
‘’ 类型: 属性
‘’ 目的: 设定或显示每页的记录数。
‘’ 输入: a_intPageSize: 每页显示的记录数。
‘’ 返回: 每页显示的记录数。
‘’*****************************************
Public Property Let PageSize(a_intPageSize)
Dim strError

‘’PageSize获取失败标志
SW_blnPageSize = false
If Trim(a_intPageSize) = "" OR (Not(IsNumeric(a_intPageSize))) Then
strError = strError & "<br>非法的pagesize"
Else
If (a_intPageSize <= 2147483647 And a_intPageSize>=-2147483648) Then
SW_intPageSize = CLng(a_intPageSize)
Else
strError = strError & "<br>PageSize溢出"
End If
If (SW_intPageSize<=0) Then
strError = strError & "<br>PageSize只能是正整数"
End If
End If
If Trim(strError)="" Then
SW_blnPageSize = True
Else
SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">PageSize属性:</font></td></tr>" & vbcrlf
SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
End If
End Property

‘’*****************************************
‘’ 类型: 属性
‘’ 目的: 设定分页文件显示模板信息。
‘’ 输入: a_strTemplate: 模板描述。
‘’ 返回: 无。
‘’*****************************************
Public Property Let Template(a_strTemplate)
Dim aryTemplate,i,j,strError,strTemp,intItem,aryTemp,aryTemp1

SW_blnTemplate = false

aryTemplate = Split(Trim(LCase(a_strTemplate)),"+")
intItem = UBound(aryTemplate)
If intItem < 4 Then strError = "<br>此属性是必选项"

If intItem < 4 Then
‘’获取文件头
strTemp = TriM(aryTemplate(0))

If strcomp(Left(strTemp,6),"[file=")= 0 Then
SW_strHeadJS = "<script src=""" & Mid(strTemp,7,Len(strTemp)-7) & """></script>"
Else
SW_strHeadJS = Mid(strTemp,7,Len(strTemp)-7)
End If

‘’获取文件尾
strTemp = Trim(aryTemplate(3))

If strComp(Left(strTemp,6),"[file=") = 0 Then
SW_strFootJS = "<script src=""" & Mid(strTemp,7,Len(strTemp)-7) & """></script>"
Else
SW_strFootJS = Mid(strTemp,7,Len(strTemp)-7)
End If

‘’获取分页模版
aryTemp = Split(aryTemplate(1),",")
If aryTemp(0) <> "" Then strTemp = Replace(aryTemp(0),"[page=","")

If IsNumeric(strTemp) Then strTemp = CInt(strTemp)
If strTemp <> SW_intPageInNone Then

If IsNumeric(strTemp) Then strTemp = CInt(strTemp)

SW_intShowPagePos = strTemp
strTemp = aryTemp(1)
If strTemp <> "" Then strTemp = Replace(strTemp,"]","")

If IsNumeric(strTemp) Then strTemp = CInt(strTemp)
SW_intShowPageType = strTemp
Else
SW_intShowPagePos = SW_intPageShowInNone
End If

‘’获取数据显示模版
aryTemp = Split(aryTemplate(2),"|")
For i = 0 To UBound(aryTemp)
strTemp = LCase(Trim(aryTemp(i)))
Select Case i
Case 0 ‘’获取并设置显示宽度
If strTemp <> "" Then strTemp = Replace(strTemp,"[data=","")
SW_strShowWidth = strTemp
Case 1 ‘’获取数据显示方式
If IsNumeric(strTemp) Then strTemp = CInt(strTemp)
SW_intShowType = strTemp
Case 2
If strTemp <> "" Then strTemp = Replace(strTemp,"]","")
aryTemp1 = Split(Trim(strTemp),"#")
If UBound(aryTemp1) >= 3 Then
SW_aryFldNote = Split(aryTemp1(0),",")
SW_aryFldAlign = Split(aryTemp1(1),",")
SW_aryFldWidth = Split(aryTemp1(2),",")
SW_aryFldLink = Split(aryTemp1(3),",")
End If
End Select
Next
End If

If strError = "" Then
SW_blnTemplate = true
Else
SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">Template属性:</font></td></tr>" & vbcrlf
SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
End If
End Property

‘’*****************************************
‘’ 类型: 属性
‘’ 目的: 设定或显示URL。
‘’ 输入: a_strURL: 需要分页的文件地址。
‘’ 返回: 需要分页的文件地址。
‘’*****************************************
Public Property Let URL(a_strURL)
Dim strError,objFSO

SW_blnGetURL = false
If Trim(a_strURL)="" Then
strError = "<br>非法的URL地址"
Else
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Server.Mappath(a_strURL)) Then
SW_strURL = a_strURL
Else
strError = strError & "<br>你能确定文件 <font color=""#ff0000"">" & a_strURL & "</font> 存在么?"
End If
Set objFSO = Nothing
End If
If strError = "" Then
SW_blnGetURL = true
Else
SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">URL属性:</font></td></tr>" & vbcrlf
SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
End If
End Property


‘’*****************************************
‘’ 类型: 属性
‘’ 目的: 设置显示标题时单元格的宽度
‘’ 输入: a_strTleWidth:单元格宽度字符串
‘’ 返回: 无
‘’*****************************************
Public Property Let TleWidth(a_strWidth)
SW_strTleWidth = a_strWidth
End Property

‘’*****************************************
‘’ 类型: 属性
‘’ 目的: 设置显示标题时单元格分隔线的类型
‘’ 输入: a_intBDType 单元格分隔线的类型
‘’ 返回: 无
‘’*****************************************
Public Property Let TleBDType(a_intBDType)
SW_intTleBDType = a_intBDType
End Property

‘’*****************************************
‘’ 类型: 过程
‘’ 目的: 统计总记录数、计算总页数
‘’ 输入: 无
‘’ 返回: 无
‘’*****************************************
Sub Init()
Dim intPostion,strError,i,objRSTemp,lngTotalRecord

If Not (SW_blnConn and SW_blnOpenRS and SW_blnPageSize and SW_blnGetURL) Then
Call ShowErrors()
Exit Sub
End If

If SW_objRS.Eof And SW_objRS.Bof Then
strError = strError & "<br>库中无任何记录"
End If

‘’计算总计录数
Set objRSTemp = SW_objConn.Execute("SELECT * FROM SW_RecCount")
lngTotalRecord = CLng(objRSTemp("SW_RecCount").Value)
SW_lngTotalRecord = lngTotalRecord
If (SW_lngTotalRecord<=2147483647 AND SW_lngTotalRecord>=-2147483648) Then
SW_lngTotalRecord = CLng(SW_lngTotalRecord)
Else
strError = strError & "<br>分页初始化时:总记录数溢出"
End If
If SW_lngTotalRecord <=0 Then strError = strError & "<br>分页初始化时:总记录数小于零"

‘’计算总页数
If SW_lngTotalRecord Mod SW_intPageSize = 0 Then
SW_lngTotalPage = CLng(SW_lngTotalRecord \ SW_intPageSize * -1)*-1
Else
SW_lngTotalPage = CLng(SW_lngTotalRecord \ SW_intPageSize * -1)*-1 + 1
End If

‘’获取页数
SW_lngPageNo = Trim(Request.QueryString("pageno"))
If SW_lngPageNo = "" Then SW_lngPageNo = Trim(Request.Form("PageNo"))
If SW_lngPageNo = "" Then SW_lngPageNo = 1
‘’如果没有选择第几页,则默认显示第一页
If SW_lngPageNo <> "" And IsNumeric(SW_lngPageNo) Then
If (SW_lngPageNo <= 2147483647 And SW_lngPageNo>=-2147483648) Then
SW_lngPageNo = CLng(SW_lngPageNo)
Else
strError = strError & "<br>页数溢出,请检查!"
End If
If (SW_lngPageNo<=0) Then strError = strError & "<br>页数只能是正整数!"
Else
strError = strError & "<br>你确信此页数 <font color=""#FF0000"">" & SW_lngPageNo & "</font> 存在?"
End If

If (SW_lngPageNo > SW_lngTotalPage AND SW_lngTotalPage<>0) Then SW_lngPageNo = SW_lngTotalPage

SW_objRS.PageSize = SW_intPageSize
SW_objRS.AbsolutePage = SW_lngPageNo

intPostion = InstrRev(SW_strURL,"?")
SW_strFormAction = SW_strURL
If intPostion > 0 Then
SW_strURL = SW_strURL & "&PageNo="
Else
SW_strURL = SW_strURL & "?PageNo="
End If

If Trim(SW_strFields) = "" Then
For i = 0 To SW_objRS.Fields.Count-1
SW_strFields = SW_strFields & SW_objRS(i).Name & ","
Next
End If

SW_strFields = LCase("," & Trim(SW_strFields))
If IsArray(SW_aryFldName) Then
For i = LBound(SW_aryFldName) To Ubound(SW_aryFldName)
If Instr(SW_strFields,"," & SW_aryFldName(i) & ",") = 0 Then strError = strError & "<br>字段名 <font color=""#ff0000"">" & SW_aryFldName(i) & "</font> 正确吗?"
Next

If (IsArray(SW_aryFldNote) AND UBound(SW_aryFldName)>UBound(SW_aryFldNote)) Then strError = strError & "<br>字段相应中文说明项目不能小于字段个数"

If (IsArray(SW_aryFldWidth) AND UBound(SW_aryFldName)>UBound(SW_aryFldWidth)) Then strError = strError & "<br>字段相应宽度项目不能小于字段个数"

If (IsArray(SW_aryFldAlign) AND UBound(SW_aryFldName)>UBound(SW_aryFldAlign)) Then strError = strError & "<br>字段数据相应对齐方式项目不能小于字段个数"
If (IsArray(SW_aryFldLink) AND UBound(SW_aryFldName)>UBound(SW_aryFldLink)) Then strError = strError & "<br>字段数据相应文件链接项目不能小于字段个数"
End If

If Trim(strError) = "" Then
SW_blnInit = true
Else
SW_strError = SW_strError & " <tr bgcolor=""#336699"" height=""28""><td><font color=""#FFFFFF"">Init过程:</font></td></tr>" & vbcrlf
SW_strError = SW_strError & " <tr bgcolor=""#ffffff""><td>" & strError & "</td></tr>" & vbcrlf
End If
Response.Write(SW_strHeadJS & vbcrlf)
End Sub

‘’*****************************************
‘’ 类型: 过程
‘’ 目的: 显示分页信息
‘’ 输入: 无
‘’ 返回: 无
‘’*****************************************
Private Sub Pages()
Dim strPages,k,intTemp,intTemp1

If Not(SW_blnInit) Then Call ShowErrors()

If SW_lngTotalPage = 1 Then Exit Sub
Response.Write("<table align=""center"" class=""css_ShowPage"" width=""" & SW_strShowWidth & """>" & vbcrlf)

Response.Write(" <tr>" & vbcrlf)
Response.Write(" <td>" & vbcrlf)
Response.Write(" <table width=""100%"">" & vbcrlf)
Response.Write(" <tr>" & vbcrlf & " <td align=""center"" valign=""middle"" class="".test1"">" & vbcrlf)

If SW_lngTotalPage >= 1 Then
SELECT CASE SW_intShowPageType
Case SW_intShowChinese
If SW_lngPageNo <= 1 Then
Response.Write ("<font color=""" & SW_strFTColor & """>首页 前页 <a href=""" & SW_strURL & SW_lngPageNo+1 & """>后页</a> <a href=""" & SW_strURL & SW_lngTotalPage & """>末页</a>" & vbcrlf)
Else
If SW_lngPageNo >= SW_lngTotalPage Then
Response.Write ("<font color=""" & SW_strFTColor & """><a href=""" & SW_strURL & "1"">首页</a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """>前页</a> " & "后页 末页" & vbcrlf)
Else
Response.Write ("<font color=""" & SW_strFTColor & """><a href=""" & SW_strURL & "1"">首页</a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """>前页</a> " & "<a href=""" & SW_strURL & SW_lngPageNo+1 & """>后页</a> <a href=""" & SW_strURL & SW_lngTotalPage & """>末页</a>" & vbcrlf)
End If
End If
Response.Write (" 页次:<b>" & SW_lngPageNo & "</b>/" & SW_lngTotalPage & "页 共<b>" & SW_lngTotalRecord & "</b>条记录 <b>" & SW_intPageSize & "</b>条/页</td>" & vbcrlf)
Response.Write(" <form name=""gopage"" action=""" & SW_strFormAction & """ method=""post"">" & vbcrlf)
Response.Write(" <td> 第")
Response.Write(" <input type=""text"" name=""pageno"" size=""3"" maxlength=4 title=""请输入页号,然后回车"">页 " & vbcrlf)
Response.Write("<input type=""submit"" value=""GO""></td></form></tr>" & vbcrlf)
Case SW_intShowEnglish
If SW_lngPageNo <= 1 Then
Response.Write ("<font color=""" & SW_strFTColor & """>First Prev <a href=""" & SW_strURL & SW_lngPageNo+1 & """>Next</a> <a href=""" & SW_strURL & SW_lngTotalPage & """>Last</a>" & vbcrlf)
Else
If SW_lngPageNo >= SW_lngTotalPage Then
Response.Write ("<font color=""" & SW_strFTColor & """><a href=""" & SW_strURL & "1"">First</a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """>Prev</a> " & "Next Last" & vbcrlf)
Else
Response.Write ("<font color=""" & SW_strFTColor & """><a href=""" & SW_strURL & "1"">First</a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """>Prev</a> " & "<a href=""" & SW_strURL & SW_lngPageNo+1 & """>Next</a> <a href=""" & SW_strURL & SW_lngTotalPage & """>Last</a>" & vbcrlf)
End If
End If
Response.Write (" Page No:<b>" & SW_lngPageNo & "</b>/" & SW_lngTotalPage & " Total Records:<b>" & SW_lngTotalRecord & "</b> PageSize:<b>" & SW_intPageSize & "</b></td>" & vbcrlf)
Response.Write(" <form name=""gopage"" action=""" & SW_strFormAction & """ method=""post"">" & vbcrlf)
Response.Write(" <td> ")
Response.Write(" <input type=""text"" name=""pageno"" size=""3"" maxlength=4 title=""Please input pageno then enter""> " & vbcrlf)
Response.Write("<input type=""submit"" value=""GO""></td></form></tr>" & vbcrlf)
Case SW_intShowCharacter
strPages = ""
intTemp = (SW_lngPageNo \ SW_intShowPages) * SW_intShowPages
If SW_lngPageNo Mod SW_intShowPages = 0 Then intTemp = intTemp - 10
For k = 1 To SW_intShowPages
intTemp1 = intTemp + k

If intTemp1 > SW_lngTotalPage Then Exit For
If SW_lngPageNo = intTemp1 Then
If Len(Trim(CStr(intTemp1)))<2 Then
strPages = strPages & " 0" & CStr(intTemp1)
Else
strPages = strPages & " " & CStr(intTemp1)
End If
Else
strPages = strPages & " <a href=""" & SW_strURL & CStr(intTemp1) & """>"
If Len(Trim(CStr(intTemp1)))<2 Then
strPages = strPages & "0" & CStr(intTemp1)
Else
strPages = strPages & CStr(intTemp1)
End If
strPages = strPages & "</a>"
End If
Next
If SW_lngPageNo <= 1 Then
Response.Write ("<font face=""Webdings"">9 7</font>" & strPages & " <a href=""" & SW_strURL & SW_lngPageNo+1 & """><font face=""Webdings"">8</font></a> <a href=""" & SW_strURL & SW_lngTotalPage & """><font face=""Webdings"">:</font></a>" & vbcrlf)
Else
If SW_lngPageNo >= SW_lngTotalPage Then
Response.Write ("<a href=""" & SW_strURL & "1""><font face=""Webdings"">9</font></a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """><font face=""Webdings"">7</font></a>" & strPages & " <font face=""Webdings"">8 :</font>" & vbcrlf)
Else
Response.Write ("<a href=""" & SW_strURL & "1""><font face=""Webdings"">9</font></a> <a href=""" & SW_strURL & SW_lngPageNo -1 & """><font face=""Webdings"">7</font></a> " & strPages & " <a href=""" & SW_strURL & SW_lngPageNo+1 & """><font face=""Webdings"">8</font></a> <a href=""" & SW_strURL & SW_lngTotalPage & """><font face=""Webdings"">:</font></a>" & vbcrlf)
End If
End If

Response.Write ("</td>" & vbcrlf)
Response.Write(" <form name=""gopage"" action=""" & SW_strFormAction & """ method=""post"">" & vbcrlf)
Response.Write(" <td> ")
Response.Write(" <input type=""text"" name=""pageno"" size=""3"" maxlength=10 title=""Please input pageno then enter""> " & vbcrlf)
Response.Write("<input type=""submit"" value=""GO""></td></form></tr>" & vbcrlf)
‘’ Case SW_intShowImage
Case Else
Response.Write("<br>对不起,你设置的显示方式SWPage不支持。")
Response.End
End Select
End If
Response.Write(" </table>" & vbcrlf)
Response.Write(" </td>" & vbcrlf)
Response.Write(" </tr>" & vbcrlf)
Response.Write("</table>" & vbcrlf)
End Sub

‘’*****************************************
‘’ 类型: 过程
‘’ 目的: 显示分页数据
‘’ 输入: 无
‘’ 返回: 无
‘’*****************************************
Sub Show()
Dim i,j

If Not(SW_blnInit) Then Call ShowError()

j = 0
If SW_objRS.Eof And SW_objRS.Bof Then
Response.Write("库中无任何记录<br>")
Response.End
Else
If SW_intShowPagePos = SW_intPageInAll Or SW_intShowPagePos = SW_intPageInTop Then Call Pages()

‘’空行
Response.Write("<table><tr><td height=""5""></td></tr></table>" & vbcrlf)

SELECT CASE SW_intShowType
Case SW_intHorizontalView ‘’横排
Do While (Not SW_objRS.Eof AND j<SW_intPageSize)
Response.Write(" <table class=""css_showdata_tb"" width=""" & SW_strShowWidth & """ align=""center"">" & vbcrlf)
For i = LBound(SW_aryFldName) To UBound(SW_aryFldName)
Response.Write(" <tr class=""css_showdata_title_H"" height=""28"">" & vbcrlf)
Response.Write(" <td class=""css_showdata_V"" align=""center"" width=""" & SW_strTleWidth & """>" & vbcrlf & "")
If (IsArray(SW_aryFldNote)) Then
Response.Write(SW_aryFldNote(i) & vbcrlf)
Else
Response.Write(SW_aryFldName(i) & vbcrlf)
End If

Response.Write(" </td>" & vbcrlf & " <td class=""css_showdata_td"" ")

If (IsArray(SW_aryFldWidth)) Then Response.Write(" width=""" & SW_aryFldWidth(i) & """")

If (IsArray(SW_aryFldAlign)) Then Response.Write(" align=""" & SW_aryFldAlign(i) & """")

Response.Write(">" & vbcrlf)

If (IsArray(SW_aryFldLink) AND (Trim(SW_aryFldLink(i))<>"")) Then
Response.Write("<a href=""" & SW_aryFldLink(i) & """ target=""_blank"">" & SW_objRS(SW_aryFldName(i)) & "</a></td>" & vbcrlf)
Else
Response.Write(SW_objRS(SW_aryFldName(i)) & "</td>" & vbcrlf)
End If

Response.Write(" </tr>" & vbcrlf)
Next
Response.Write(" </table>" & vbcrlf)
‘’空行
Response.Write("<table><tr><td height=""5""></td></tr></table>" & vbcrlf)
SW_objRS.MoveNext
j = j + 1
Loop
CASE SW_intVerticalView ‘’竖排
If SW_intTleBDType = SW_intTleNoBorder Then
Response.Write(" <table class=""css_showdata_tb"" align=""center"" width=""" & SW_strShowWidth & """>" & vbcrlf)
Response.Write(" <tr class=""css_title""><td colspan=""" & CStr(UBound(SW_aryFldName)+1) & """>" & vbcrlf)
Response.Write(" <table border=""0"" width=""100%""><tr>")
For i = LBound(SW_aryFldName) To UBound(SW_aryFldName)
Response.Write(" <td align=""center""")
If (IsArray(SW_aryFldWidth)) Then Response.Write(" width=""" & SW_aryFldWidth(i) & """>")
If (IsArray(SW_aryFldNote)) Then
Response.Write(SW_aryFldNote(i) & vbcrlf)
Else
Response.Write(SW_aryFldName(i) & vbcrlf)
End If
Response.Write(" </td>" & vbcrlf)
Next
Response.Write(" </tr></table></td></tr>" & vbcrlf)
Else
Response.Write(" <table class=""css_showdata_tb"" width=""" & SW_strShowWidth & """ align=""center"">" & vbcrlf)
Response.Write(" <tr class=""css_Title"" height=""28"">" & vbcrlf)
For i = LBound(SW_aryFldName) To UBound(SW_aryFldName)
Response.Write(" <td class=""css_showdata_td"" align=""center""")
If (IsArray(SW_aryFldWidth)) Then Response.Write(" width=""" & SW_aryFldWidth(i) & """>")
If (IsArray(SW_aryFldNote)) Then
Response.Write(SW_aryFldNote(i))
Else
Response.Write(SW_aryFldName(i))
End If
Response.Write(" </td>" & vbcrlf)
Next
Response.Write(" </tr>" & vbcrlf)
End If

Do While (Not SW_objRS.Eof AND j<SW_intPageSize)
Response.Write(" <tr class=""CSS_ShowData_tr"" height=""28"">" & vbcrlf)
For i = LBound(SW_aryFldName) To UBound(SW_aryFldName)
Response.Write( "<td class=""css_showdata_td""")
If (IsArray(SW_aryFldAlign)) Then Response.Write(" align=""" & SW_aryFldAlign(i) & """ width=""" & SW_aryFldWidth(i) & """>")
If (IsArray(SW_aryFldLink) AND Trim(SW_aryFldLink(i)<>"")) Then
Response.Write(" <a href=""" & SW_aryFldLink(i) & """ target=""_blnak"">" & SW_objRS(SW_aryFldName(i)) & "</a></td>")
Else
Response.Write(SW_objRS(SW_aryFldName(i)) & " </td>" & vbcrlf)
End If
Next

Response.Write(" </tr>" & vbcrlf)
SW_objRS.MoveNext
j = j + 1
Loop
Response.Write(" </table>" & vbcrlf)
Response.Write("<table><tr><td height=""5""></td></tr></table>" & vbcrlf)
CASE ELSE
Response.Write("<br>你还没设置数据的显示方式?或者你的设置的显示方式SWPage不支持!<br>")
Response.End
End SELECT
If SW_intShowPagePos = SW_intPageInAll Or SW_intShowPagePos = SW_intPageInBottom Then Call Pages()
Response.Write( SW_strFootJS & vbcrlf)
End If
End Sub

‘’*****************************************
‘’ 类型: 过程
‘’ 目的: 显示分页类中出现的错误信息
‘’ 输入: 无
‘’ 返回: 无
‘’*****************************************
Private Sub ShowErrors()
If SW_strError <> "" Then
SW_strError = "<table bgcolor=""#0000"" cellspacing=""1"" cellpadding=""0"" width=""90%"" align=""center"">" & vbcrlf & " <tr bgcolor=""#ff9900"" height=""30""><td align=""center"" valign=""middle""><b>SWPage分页类错误信息<b></td></tr>" & vbcrlf & SW_strError & "</table>" & vbcrlf
Response.Write(SW_strError)
Response.End
End If
End Sub

‘’*****************************************
‘’ 类型: 过程
‘’ 目的: 释放资源
‘’ 输入: 无
‘’ 返回: 无
‘’*****************************************
Sub Close()
Set SW_objRS = Nothing
Set SW_objConn = Nothing
End Sub
End Class
%>




三、类的应用代码
<%Option Explicit
Dim strStartTime,intUseTime,clsPage,strShowTemp
strStartTime = timer()
%>
<!--#include file="inc_clsPages.asp"-->
<%
‘’分页显示的位置:SW_intPageInAll,SW_intPageInTop,SW_intPageInBottom
‘’页数的显示模式:SW_intShowChinese,SW_intShowEnglish,SW_intShowCharacter,SW_intShowImage


‘’页面显示模板设置 <文件头> + <页数设置:分页显示模式,页数显示的位置> + <数据显示> + <页数显示> + <文件尾>如果某项不需要,只要设置成<>就行了,不过<文件头>和<文件尾是必须的>

‘’设置分页文件头,可以直接跟HTML代码({code=<html>....</html>})
strShowTemp = "[file=head.js] + "
‘’设置分页条显示信息
strShowTemp = strShowTemp & "[page=" & SW_intPageInAll & "," & SW_intShowCharacter & "] + "

‘’########设置数据模版信息
strShowTemp = strShowTemp & "[data="
‘’设置显示的宽度
strShowTemp = strShowTemp & "90%|"
‘’数据显示方式,竖排、横排
strShowTemp = strShowTemp & SW_intVerticalView & "|"

‘’需要显示的字段的相应的中文说明
strShowTemp = strShowTemp & "编号,用户名,生日#"
‘’需要显示的字段的相应的对齐方式
strShowTemp = strShowTemp & "left,center,right#"
‘’需要显示的字段的相应的宽度
strShowTemp = strShowTemp & "30%,30%,30%#"
‘’需要显示的字段的相应的链接文件名
strShowTemp = strShowTemp & "list.asp,,,"

strShowTemp = strShowTemp & "] + "
‘’#########数据模版结束

‘’#########设置文件尾
strShowTemp = strShowTemp & "[file=foot.js]"

Set clsPage = New SWPage
clsPage.Conn = "Driver={Microsoft Aclearcase/" target="_blank" >ccess Driver (*.mdb)};dbq=" & Server.Mappath("../db/datatest.mdb")
clsPage.SQL = "SELECT * FROM datatest"
clsPage.PageSize = 10
clsPage.URL = "pages.asp"
clsPage.FieldList = "id,field1,field2"
clsPage.Template = strShowTemp ‘’显示模版
clsPage.Init()
clsPage.Show
clsPage.Close
Set clsPage = Nothing

intUseTime = FormatNumber((timer()-strStartTime)*1000,3)
Response.Write("<br><br><center>共用时 <font color=""#FF0000"">" & intUseTime & "</font> 毫秒</center>")
%>



四、注意事项
  你可以随意修改、使用此代码,但是当你修改后,希望能给我一份拷贝(cjj8110@xxx163.com为了防止垃圾邮件,发邮件时请把163前面的"xxx"删除)。如在使用中发现有Bug请通知我或帮我改正,需要注意的是本类需要用到FSO,主要是URL属性中用到它。现在不使有RecordSet对象的RecordCount属性来获取总记录数了,而是将总记录数存在另外的一个表中,所以在通用方面降低了很多,有兴趣的朋友也可以用Application对象来记录总记录数。不管哪种方法,都使添加记录、删除记录的操作麻烦起来了,但分页中最耗时的地方就是用RecordCount来取总记录数了,当然如果你的库记录数不多的话,是无所谓的。但如果有几十或几百万条记录时,可以很明显的感觉到用不用RecordCount的区别了。


原文转自:http://www.ltesting.net