开店乐

开店乐电子商务研究 KaiDianLe.Com

网站地图 :

  搜索:

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 Access 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的区别了。

【日期:2006-8-7】【作者:不祥】【转载自:开店乐】

相关文章:
 最好的网上开店系统:凡人网络购物系统免费下载
 Rs.open sql,conn,A,B 的A、B各代表什么?
 ASP开发中存储过程应用全接触
 Oracle大文本在ASP中存取问题的解决
 数据分页方法新思路,速度非常快!
 ASP+vbscript写的万能查询表达式生成器
 常用网站数据库SQL操作语句
 ASP程序与SQL存储过程详解
 ASP脚本一空间绑定多个域名代码
 WEB编程开发常用的代码大全
 解决大字段在Form中Post出错的方法
 学习ASP之编写安全的ASP代码
 ASP程序应用之模板采用
 防止别人批量采集功能的ASP代码
 网页图片下拉选择控件使用实例
 平时写程序的时候出错时的解决方法
 “在线访客”的制作方法
 ASP中数据库调用时常见错误的现象和解决
 ASP 编程中20个非常有用的例子
 经典实用的基础asp程序整理
 ASP中从数据库读取二进制文件数据代码
 ASP动态生成的javascript表单验证代码
 在电子商务中实现购物车的方法
 ASP利用Google实现在线翻译功能
 实现千万级数据分页的存储过程
 详细说明用ASP和WML来实现数据库查询
 ASP访问INTERBASE数据库
 ASP安全配置不完全手册
 在ASP中如何访问Novell下的数据库
 ASP进阶学习必经之认识数学函数11种
 初学者必读 ASP运行环境的搭建
 解析asp的脚本语言
 学习使用ASP对象和组件
 让ASP程序运行于非Windows平台
 通过启动脚本来感受ASP的力量
 一些不长见的ASP调用存储过程的技巧
 使用ASP脚本技术
 优化Web数据库页面
 Asp限制IP访问代码
 ACCESS数据库防下载另类方法
 ASP浏览器性能组件
 细说ASP中Counters 组件
 全面解析Server对象
 ASP 内建对象Request和Respones
 深入研究Application和Session对象
 使用ASP、VB和XML建立运行于互联网上的应用程序
 在客户端执行数据库记录的分页显示
 对ASP脚本源代码进行加密
 用代码打开Access文件的两种方法
 使用Visual InterDev进行小组开发
 用JScript脚本实现分页的另类办法
 ASP中Cookie读写的实现方法
 如何使用ASP建立虚拟的FTP服务器
 在ASP中自动创建多级文件夹的函数
 一个硬盘文件搜索的Asp源码
 ASP使用MYSQL数据库全攻略
 ASP上传数据流格式分析详解
 ASP汉字转换UTF-8及UTF-8转换GB2312
 ASP常用数据库连接及操作的方法
 ASP编程中常用SQL命令使用方法
 ASP查询记录时RecordCount=-1问题
 让你的WAP网站有更好的兼容性
 如何注册服务器端组件
 轻松实现任何程序和动易整合
 在服务器端调用winzip命令行对上传的多个文件打包压缩
 用ASP制作强大的搜索引擎
 ASP彩色校验码的制作
 ASP 系列函数大全
 ASP程序处理进程进度条
 Asp无组件生成缩略图
 用ASP实现自动建站.实现虚拟二级目录
 删除Access数词库中的空记录
 ASP身份证验证代码函数
 ASP写的自动生成SELECT表单的函数
 几种打开记录集方式的比较
 用ASP实现汉字转拼音的功能
 ASP分页代码,已经写成类了,值得参考
 ASP下载系统防盗链方法
 Global.asa文件用法大全
 如何防止页面中的敏感信息被提取
 Delphi编写组件封装asp代码的基本步骤
 制做行背景颜色交替变换的表格
 如何用foreach遍历页面上所有的TextBox
 将数据库中的信息存储至XML文件中
 用Asp写个加密和解密的类
 如何固定表格的标题行和标题列
 ASP小偷(远程数据获取)程序入门教程
 Asp编写不再让人讨厌的自动弹出窗口
 用ASP实现在线压缩与解压缩
 使用组件封装ASP的数据库操作
 ASP中读写注册表
 ASP判断函数一览及网页制作常用技术
 ASP中Cookie使用指南
 随机产生用户密码(good)
 ASP:如何对身份证的籍贯进行验证
 ASP产生随机密码的函数
 ASP+ADO实现数据读写简单示例
 一个简单的用户登录接口ASP实现
 ASP+SQL Server构建网页防火墙
 一个通用的保护ASP系统的方法
 利用ASP发送和接收XML数据的处理方法

版权所有:Kaidianle.Com  联系方式:Shnxn@Yhaoo.Com.Cn 京ICP备06028743号 在线留言