ASP分页代码,已经写成类了,值得参考 转自 cuiwl 的 Blog

实现自动分页功能的ASP代码解析 在信息展示场景中,当内容量较大时,一次性加载所有数据会导致性能下降和用户体验恶化。分页,作为一种信息组织和展示的策略,将大量数据划分为较小、更易于管理的块。每一块数据被称为“一页”,用户可以通过分页功能在不同的数据页之间切换,从而只加载当前页面所需的数据。分页的主要作用在于:- 提高页面加载速度:仅加载当前页面的数据,减少网络传输量和服务器负载。- 改善用户体验:用户可以快速找到他们感兴趣的数据部分,而不是在大量数据中滚动或搜索。 阅读详情
 

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>")
%>



四、注意事项
  需要注意的是本类需要用到FSO,主要是URL属性中用到它。现在不使有RecordSet对象的RecordCount属性来获取总记录数了,而是将总记录数存在另外的一个表中,所以在通用方面降低了很多,有兴趣的朋友也可以用Application对象来记录总记录数。不管哪种方法,都使添加记录、删除记录的操作麻烦起来了,但分页中最耗时的地方就是用RecordCount来取总记录数了,当然如果你的库记录数不多的话,是无所谓的。但如果有几十或几百万条记录时,可以很明显的感觉到用不用RecordCount的区别了。

ASP通用分页代码模块:跨程序兼容实现 在信息处理中,分页功能是Web应用程序不可或缺的一部分,尤其当数据量庞大时,它能够帮助用户更有效地浏览信息。ASP (Active Server Pages) 是一种服务器端脚本环境,它允许开发者使用HTML、脚本命令以及ActiveX组件来创建动态网页。在本章中,我们将对ASP通用翻页代码模块进行概述,为后续章节的深入讨论和实现奠定基础。翻页功能的核心在于为用户提供清晰的页面导航,同时优化服务器性能和响应时间。 阅读详情

相关推荐

asp数字分页代码

asp数字分页代码,已通过测试,可直接使用。分页格式:上一页1-2-3…9下一页

ASP分页代码

分页代码<% rs.pagesize = 20 //每页显示多少条信息 page = request.querystring("page") //接收当前的页面值 if page ="" then page = 1 //判断页面值为空,那么就转到第一页 if isnumeric(page) then //判断不是数字

橙色卡布奇诺 4943

Abaqus仿真突然中断?手把手教你解决SIGTERM/SIGINT报错(附完整命令行方案)

本文深入解析Abaqus仿真中因SIGTERM或SIGINT信号导致进程意外中断的根本原因,并提供了一套完整的命令行解决方案。通过将作业提交方式从图形界面切换到命令行,并配合关键参数设置,可以有效避免因会话空闲超时或外部干扰引发的计算中断,保障长时间仿真任务的稳定运行。

devops8pract的博客 755

asp分页代码(最实用的)

平时常用的分页代码!放上去备忘啊,每次用都要找,老是记不住,现在copy一下,改改参数就可以了! 分页代码一 <% page=request("page") count=rs.recordcount if count<1 then response.write "<br /> <center>数据库中没有资料!</center&gt...

weixin_33858485的博客 297

LangGraph的容错机制:从节点失败到图级回滚

核心概念铺垫:讲解LLM应用容错与事务性的核心概念(幂等性、重试策略、降级策略、快照、回滚、原子性、一致性、隔离性、持久性、最终一致性),对比LangGraph容错机制与传统数据库ACID事务、Apache Airflow/Kubernetes Workflow/Kubeflow Pipelines容错机制的异同;LangGraph容错机制的演进历史:用markdown表格梳理LangGraph从0.0.1到1.5.0(截止202X年X月)的容错机制发展历程;节点级别的容错:重试与降级。

AI Python 编程之道的博客 182

STM32 LwIP协议栈优化:从TCP延迟10ms降至1ms的内存配置手册

摘要: 本文针对STM32嵌入式开发中LwIP TCP通信的高延迟问题(默认配置下延迟达10~20ms),提出纯软件优化方案,通过调整内存配置与TCP参数将延迟降至1ms。核心问题包括内存池不足、pbuf分配低效及Nagle算法拖累,优化步骤包括: 内存池扩容:增大MEMP_NUM_TCP_PCB至10、PBUF_POOL_SIZE至32,避免资源竞争; pbuf静态池分配:采用2048字节大块缓冲区匹配DMA传输,减少分块与拷贝; 关闭Nagle算法:设置TCP_NODELAY=1,禁用延迟确认以加速小包

weixin_42212753的博客 1715

asp 简单分页代码

<% set rs=server.createobject("adodb.recordset") exce="sql" 'sql 查询语句 rs.open exce,conn,1,1 %> 然后是分页属性的设置 <% rs.PageSize=3 ‘设置页码 pagecount=rs.PageCount '获取总页码 page=int(request("page")) '接收页码

void_1987的专栏 659

嵌入式SPI总线抽象设计:跨平台驱动与分层解耦实践

SPI(串行外设接口)是嵌入式系统中应用最广泛的同步串行通信协议,其核心价值在于高吞吐、低开销与硬件简洁性。其工作原理基于主从架构、全双工/半双工时序及片选(CS)控制,依赖CPOL/CPHA组合定义四种标准模式。在工程实践中,SPI常面临硬件资源受限、多外设共用总线、MCU平台迁移等挑战,导致驱动复用率低、维护成本高。通过结构体+函数指针实现的分层抽象——将物理总线、协议适配与设备驱动解耦,可显著提升代码可移植性与扩展性。该方法天然支持硬件SPI与GPIO模拟SPI双模式切换,并已在STM32等主流MCU

weixin_42601134的博客 66

asp完美分页代码

rs.PageSize = 翻页数     rs.CursorLocation = 3rs.Open sql,conn,0,2,1 pre = truelast = truepage = trim(Request.QueryString("page"))    if len(page) = 0 then    intpage = 1    pre = falseelse    if cint(pa

snlixing的专栏 907

【PySide6拓展】初识QChart图表

在 PySide6 中,QtCharts模块提供了一系列强大的类,用于创建和管理图表。QChart是这个模块的核心类,它可以帮助开发者轻松地实现数据的可视化。本篇文章将介绍如何使用 PySide6 的QtCharts模块,并通过一个简单的示例教你如何快速引入QChart。QChart折线图柱状图饼图区域图它能够直观地呈现数据,同时支持交互功能,如缩放、拖拽和工具提示等。通过引入QChart,我们可以轻松实现数据的可视化,提升应用的交互性和用户体验。结合其他QtCharts。

m0_62599305的博客 825

【异常】OpenClaw提示异常 1302:您的账户已达到速率限制,请您控制请求频率

摘要:系统返回1302错误码提示"账户已达到速率限制",表明请求频率超过服务阈值。主要原因是并发请求数达上限或请求过于密集。解决方案包括:降低并发请求量、引入请求队列机制平滑流量,或根据服务规则提升账户权益等级以获取更高并发额度。建议优先优化请求频率控制策略,避免触发系统限流机制。

奶爸的编程之路,也就一周冷个三天 1169

asp 分页代码

使用asp作东西已经比较多了,但是一直没有注意这个东西,今天就花了一点时间写了一些,方便以后使用。 Dim rsTotal,rsPageSize,rsPageCount If NOT ISObject(objRs) Then Exit Sub:End If If NOT IsNumeric(rsPageSize) Then Exit Sub:End IF If objRs.Eof And objR

孤剑之家 2454

Qt Bridge for Figma

《QtBridge for Figma设计开发协作工具详解》摘要(149字) QtBridge for Figma是连接Figma设计工具与Qt框架的官方插件,实现UI设计到QML代码的自动化转换。核心功能包括:自动生成QML代码、设计系统变量提取、资源文件导出,支持双向同步和组件映射。工作流程涵盖设计标注、配置导出和代码生成三阶段,提供设计令牌、响应式布局等高级特性。该工具支持Qt5.15+/6.0+版本,通过标准化协作流程显著提升设计开发效率,确保视觉与代码一致性,适用于中英文项目开发。

追赶时代的博客 526

ASP通用分页类[转]

一、类的属性、方法   这是一个ASP通用分页类。你可以用它方便的给记录集分页,当然在网上有许多的分页类和分页函数。本分页主要有Conn、SQL、URL、FieldList、PageSize、Template、Init、Show、Close等属性和方法。   1.Conn属性    :用来获取一个已创建的Connection对象。   2.SQL属性      :根据传入的SQL语句,自动创建Re

发现之旅 2296

wireshark提取视频数据之RTP包中提取H264和H265

本文主要描述从wireshark包数据中提取出H264和H265裸流数据方法,裸流通过RTP封包方式发送,从抓包中直接提取视频流数据,进而进行流媒体问题定位

技术控的笔记 17万+

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

asp分页代码

 dim page    page=request("page")                                                        PageSize = 5读取数据库rs.open sql,conn,1,1 rs.PageSize = PageSize    分页处理     totalfilm=rs.recordcount    pgn

lhf0301的专栏 533

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

asp万用分页程序代码

这只是个asp小技巧类的东西,它虽然适合在每个不同文件名里调用这个函数,但是也是有前提的,下面让我们来仔细看看其中的原委。 下面这段是基本的分页代码: <% sql = "select……………………省略了sql语句  Set rs=Server.Createobject("ADODB.RECORDSET")  rs.Open sql, conn, 1, 1  if not rs.eof then...

lomo_2019的博客 254

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

最简单的ASP分页代码

<%set rs=Server.CreateObject("ADODB.RecordSet") sql="select * from news order by id desc"rs.open sql,conn,3,1rs.pagesize=10if request("page")<>"" then epage=cint(request("page"))...

aixinyong2525的博客 177

ASP - 三种常用分页

前段时间一直被公司后台数据翻页卡顿的问题困扰,因为数据量比较大,使用的是Adodb的Recordset对象进行数据遍历。 当时猜测是由于Recordset每次都读取了所有数据,并且每次翻页都刷新了页面,没有利用Recordset的缓存优势进行翻页,所以导致数据加载非常慢。 解决办法: 1. Recordset + JS无刷新翻页 使用Recordset方式,由于是因为Recordset的缓存没有得...

qq_19250999的博客 626

ASP内容分页的几种方法,ASP记录内容太长,就用这几种分页方法

调用请用注意:rs("PaginationType")是分页种类,写入数据库.rs("Content")是内容,rs("ArticleID")是文章ID.0 不分页1 自动2 手动(用[NextPage]分隔)****************************************************============================

我本无名的专栏 1672

asp快速分页代码

option explicit '强制定义变量 dim idcount'记录总数 dim pages'每页条数 dim pagec'总页数 dim page'页码 dim pagenc '每页显示的分页页码数量=pagenc*2+1 pagenc=2 dim pagenmax '每页显示的分页的最大页码 dim pagenmin '每页显示的分页的最小页码 page=clng(r

ymuyou有木有博客 648

asp简单分页代码

首先是recordset的创建 set rs=server.createobject("adodb.recordset") exce="sql" sql 查询语句rs.open exce,conn,1,1 %> 然后是分页属性的设置 rs.PageSize=3 ‘设置页码pagecount=rs.PageCount   获取总页码page=int(request("page")) 接收页码i

anbs01的专栏 724

ASP通用分页类

http://wediy.cn/develop/Asp/2006-4-9/k5262.htmlASP通用分页类  一、类的属性、方法   这是一个ASP通用分页类。你可以用它方便的给记录集分页,当然在网上有许多的分页类和分页函数。本分页主要有Conn、SQL、URL、FieldList、PageSize、Template、Init、Show、Close等属性和方法。   1.Con

xqf222的专栏 4436

ASP分页详解

          如果你使用过目前众多网站上的电子公告板程序的话,那你应该会知道电子公告板程序为了提高页面的读取速度,一般不会将所有的帖子全部在一页中罗列出来,而是将其分成多页显示,每页显示一定数目的帖子数,譬如 20 条。想不想了解如何实现分页显示?请看本文!  那么究竟如何才能做到将数据库的查询结果分页显示呢?其实方法有很多,但主要有两种:  一、将数据库中所有符合查询条件的记录一次性的都读

我的生活,我的BLOG 1391
上一篇: ASP常用函数收藏(转自qihboy 的 Blog )
下一篇: 常用ASP代码 转自 Newrocky 的 Blog
zhenze
博客等级 码龄23年 0粉丝 12原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值