zoukankan      html  css  js  c++  java
  • 分页显示类源代码

    <%'用法

    Dim Pages'定义类变量
    Set Pages = New Cls_Pages_New
    Pages.intPage= Page'当前页码
    Pages.RequestPage = 10'每页显示多少页的翻页数
    Pages.ShowNum=10'每页显示的记录数
    Pages.Other = Zr.QueryString'多个URL变量
    Rs = Pages.ResultSet(sql)'类输出的结果
    RecordCount=Pages.intReCun'总记录数
    If IsNull(Rs) Then   Rs = "<br>尚无任何内容"'为空则没有记录
    If IsArray(rs) Then
    For i=0 To ubound(Rs,2)
    '循环体内容为结果输出
    Next
    End If
    %>

    <%=Pages.ShowPages()%>分页输出

    <%

    Class Cls_Pages_New
       Private intRspagesize,intPaCun,intPageCun,intPageDown,intpageup,page
       Private Rs,TOther
       Public intReCun
    '初始化
       Private Sub Class_Initialize()
         intRspagesize=20'每页显示的记录数
    intPageCun=10'每页显示多少页
    intReCun=-1'总记录数
       End Sub
    '结束
       Private Sub Class_Terminate()
       End Sub


    '取得当前页
       Public Property Let intPage(ByVal VShowNum)
         page=CheckNum(VShowNum,10,-1)
    if IsNumeric(page) then'页码为整数
        page=cint(page)
        if page<1 then page=1
    else
        page=1
    end if
       End Property
    '取得每页显示条数
       Public Property Let ShowNum(ByVal VShowNum)
           intRspagesize=CheckNum(VShowNum,10,-1)
       End Property
    '取得每页显示页数
       Public Property Let RequestPage(ByVal VShowNum)
           intPageCun=CheckNum(VShowNum,10,-1)
       End Property
    '取得URL上的其他参数
       Public Property Let Other(ByVal Tor)
         If Tor="" Or IsNull(Tor) Then
           TOther=""
         Else
           TOther=Tor & "&"
         End If
       End Property
    '输出结果数组
       Public Property Get ResultSet(ByVal sql)
         ResultSet=Null
    If Not IsObject(Conn) Then ConnectionDatabase
    Set Rs = Server.CreateObject ("Adodb.Recordset")
    Rs.CursorLocation = 3
    On Error Resume Next
    Rs.Open sql,Conn,1,1,&H0001'&H0001表示adCmdText,将执行一段sql,&H0002表示adCmdTable,将操作一个表
    If Err Then
       err.Clear
       Set Conn = Nothing
       Response.Write "查询数据的时候发现错误,请检查您的查询代码是否正确。"
       Response.End
    End If
    If Not Rs.Eof Then
    Rs.pagesize=intRspagesize
    intReCun=Rs.Recordcount'总记录数
    intPaCun=Rs.pagecount'总页数
    Rs.absolutepage=page
    ResultSet=Rs.GetRows(intRspagesize)
    End If
    Rs.Close
    Set Rs=Nothing
    'Rs.AbsolutePosition = ( TmpPage - 1)* TShowNum + 1
    Zr.SqlQueryNum = Zr.SqlQueryNum+1
       End Property
    '
       Private Function CheckNum(byVal iStr,byVal iStartNum,byVal iEndNum)
         If Not IsNumeric(iStr) Then
           CheckNum=iStartNum
         Else
           CheckNum=Clng(iStr)
         End If
         If iEndNum>-1 Then
           If CheckNum<iStartNum Then CheckNum=iStartNum
           If CheckNum>iEndNum Then CheckNum=iEndNum
         End If
       End Function
    '显示分页栏目
       Public Function ShowPages()
         Dim HTMLtext
    If intPaCun<intPageCun Then intPageCun=intPaCun
    If page<>1 Then'显示第一页
    HTMLtext=HTMLtext&"<a href=""?"&TOther&"page=1"" title=""第一页""><font style=""font-family:webdings"">9</font></a>"&Chr(13)&Chr(10)
    Else
    HTMLtext=HTMLtext&"<font style=""font-family:webdings"">9</font>"&Chr(13)&Chr(10)
    End If
    If page>intPageCun Then'显示上多页
    HTMLtext=HTMLtext&"<a href=""?"&TOther&"page="&page-intPageCun&""" title=""上"&intPageCun&"页""><font style=""font-family:webdings"">7</font></a>"&Chr(13)&Chr(10)
    Else
    HTMLtext=HTMLtext&"<font style=""font-family:webdings"">7</font>"&Chr(13)&Chr(10)
    End If
    If page>1 Then'显示上一页
    HTMLtext=HTMLtext&"<a href=""?"&TOther&"page="&page-1&""" title=""上一页""><font style=""font-family:webdings"">3</font></a>"&Chr(13)&Chr(10)
    Else
    HTMLtext=HTMLtext&"<font style=""font-family:webdings"">3</font>"&Chr(13)&Chr(10)
    End If

    If intPageCun mod 2 =1 Then
    intpageup=(intPageCun-1)/2
    intPageDown=intpageup
    Else
    intpageup=intPageCun/2-1
    intPageDown=intpageup+1
    End If
    If page<=intpageup Then
    intpageup=page-1
    intPageDown=intPageCun-intpageup-1
    End If
    If (intPaCun-page)<=intPageDown Then
    intPageDown=(intPaCun-page)
    intpageup=intPageCun-intPageDown-1
    End If
    For i=intpageup To 1 Step -1
    HTMLtext=HTMLtext&"<a href=""?"&TOther&"page="&(page-i)&""" title=""第"&(page-i)&"页"">"&(page-i)&"</a>"&Chr(13)&Chr(10)
    Next
    HTMLtext=HTMLtext&"<font>"&page&"</font>"&Chr(13)&Chr(10)'当前页
    For i=1 To intPageDown
    HTMLtext=HTMLtext&"<a href=""?"&TOther&"page="&(page+i)&""" title=""第"&(page+i)&"页"">"&(page+i)&"</a>"&Chr(13)&Chr(10)
    Next

    If page<intPaCun Then'显示下一页
    HTMLtext=HTMLtext&"<a href=""?"&TOther&"page="&page+1&""" title=""下一页""><font style=""font-family:webdings"">4</font></a>"&Chr(13)&Chr(10)
    Else
    HTMLtext=HTMLtext&"<font style=""font-family:webdings"">4</font>"&Chr(13)&Chr(10)
    End If
    If page<intPaCun-intPageCun Then'显示下多页
    HTMLtext=HTMLtext&"<a href=""?"&TOther&"page="&page+intPageCun&""" title=""下"&intPageCun&"页""><font style=""font-family:webdings"">8</font></a>"&Chr(13)&Chr(10)
    Else
    HTMLtext=HTMLtext&"<font style=""font-family:webdings"">8</font>"&Chr(13)&Chr(10)
    End If
    If page<>intPaCun Then'显示最后一页
    HTMLtext=HTMLtext&"<a href=""?"&TOther&"page="&intPaCun&""" title=""最后一页""><font style=""font-family:webdings"">:</font></a>"&Chr(13)&Chr(10)
    Else
    HTMLtext=HTMLtext&"<font style=""font-family:webdings"">:</font>"&Chr(13)&Chr(10)
    End If
    ShowPages=HTMLtext
       End Function
    End Class
    %>

  • 相关阅读:
    HDinsight 系列-使用证书登陆中国区Azure
    PowerBI 应用时间智能(生成日期表)
    Hadoop 常用命令之 HDFS命令
    Hadoop分布式集群安装
    DAX:New and returning customers
    Hadoop 安装过程中出现的问题
    ftp 报错 200 Type set to A
    LC.exe 已退出,代码为-1 问题解决
    C# 文件操作
    EfRepository
  • 原文地址:https://www.cnblogs.com/lykouyi/p/5687895.html
Copyright © 2011-2022 走看看