分页类

<%
'Code by SnowBoy
'本程序参考zykj2000方法改进过来
'功能: 可以自定义每页记录数,按钮样式

'PageClass为类名
'MX_conn数据库连接
'inputsize每页记录数
'MX_RS recordset属性
'MX_SQL 查询语句
%>
<!--#include file="PageClass.inc" -->
<%
'on error resume next
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq=" & server.MapPath("DB.mdb")
'===============================================下面定义类

set PageClass=new MX_Page     '创建类
    PageClass.MX_conn=conn    'conn必需为你创建对像的名,如我上面创建名为conn
   PageCLass.MX_SQL="select id,str_table from ID order by id asc" '这里可以自定义SQL
   PageCLass.inputsize=10    '每页分几条记录'可以自定义
set VS_Rs=PageClass.MX_RS()   '创建记录集
    PageClass.show()          '输出数字

'==============================================下面自定义输出

for i=1 to PageCLass.inputsize  'inputsize=Rs.Pagesize,这里可以自定义输出数据
if not VS_Rs.eof then
    response.write VS_Rs("id")&" . "&VS_Rs("str_table")&"<br>"
    VS_Rs.movenext
else
    exit for
end if
next
%>

<style type="text/css">
<!--
table {
font-size: 12px;
color: #D25400;
text-decoration: none;
}
a:active {
font-size: 12px;
color: #FF6600;
text-decoration: none;
}
a:link {
font-size: 12px;
color: #0099CC;
text-decoration: none;
}
a:visited {
font-size: 12px;
color: #0099CC;
text-decoration: none;
}
a:hover {
font-size: 12px;
color: #FF6600;
text-decoration: blink;
}
-->
</style>
<%
    Const Str_First="<font face=webdings>9</font>"  '定义上10页按钮显示样式
    Const Str_Prev="<font face=webdings>3</font>"  '定义前一页按钮显示样式
    Const Str_Next="<font face=webdings>4</font>"  '定义下一页按钮显示样式
    Const Str_Last="<font face=webdings>:</font>"  '定义下10页按钮显示样式
    Const Str_Align="Center"     '定义分页信息对齐方式
    Const Str_Width="100%"     '定义分页信息框大小
'===============================================
Class MX_Page'类开始
Private VS_PageSize,str_erro,VS_Conn,VS_SQL,in_Rs,pageno,page

'===============================================
private Sub Class_Initialize'类初始化
        if request.querystring("PageNo")="" then'pageno为当前页
  PageNo=1
  else
  PageNo=Clng(request.querystring("PageNo"))
  End if 
End Sub
'===============================================

Public property let MX_Conn(InputConn)'指定数据库连接
       set VS_Conn=InputConn
End property
'===============================================
Public property let MX_SQL(InputSQL)'SQL语句
       VS_SQL=InputSQL
End property
'===============================================
Public property Get MX_RS()'指定记录集
       set in_Rs=Server.createobject("adodb.recordset")
    in_Rs.open VS_SQL,VS_Conn,3,2
    if in_Rs.recordcount=0 then
    Str_error=Str_error&"当前没有数据!记录为空"
    Show_Error(Str_error)
    else
    in_Rs.pagesize=inputsize
    in_Rs.AbsolutePage=PageNo
    end if
   
       set MX_RS=in_Rs
End property
'===============================================
Public Property Let inputsize(str_PageSize)'指定pagesize,当前为只写
       if isNumeric(str_PageSize) then
       VS_PageSize=clng(str_PageSize)
    else
    Str_error=Str_error&"PageSize错误,必需为数字"
    Show_Error(Str_error)
    end if
End Property
Public Property Get inputsize'当前为只读
       inputsize=clng(VS_PageSize)
End Property
'===============================================
public Sub show()'show为数字输出主要过程
        if PageNo mod inputsize<>0 then
      Page=Pageno-(PageNO Mod inputsize)+1'page为每页的开头,如1,6,11...pagesize+1
  else
      Page=Pageno-inputsize+1
  End if
    response.write "<table border=0  width="&Str_Width&"><tr><td align="&Str_Align&">"
       response.write FirstPage()
       response.write showNumber()
       response.write NextPage()
    response.write MSG()
       response.write "</td></tr></table>" 
end Sub
'===============================================
Private FunCtion FirstPage()'前10页和前一页
dim str_FirstPage,StrPage,str_FirstPage1,StrPage1
    if Page<>1 then
     strPage=Page-inputsize
     str_FirstPage="<a href="&QueURL&strPage&">"&Str_First&"</a>&nbsp;"
else
     str_FirstPage=Str_First&"&nbsp;"
end if
'==================
if PageNo<>1 then
     strPage1=PageNo-1
     str_FirstPage1="<a href="&QueURL&strPage1&">"&Str_Prev&"</a>&nbsp;"
else
     str_FirstPage1=Str_Prev&"&nbsp;"
end if
'==================
     FirstPage=str_FirstPage&"&nbsp;"&str_FirstPage1
End FunCtion
'===============================================
Private FunCtion NextPage()'下10页和下一页
dim str_NextPage,strcount,str_NextPage1,strcount1
    if in_Rs.PageCount-page>=inputsize then
     strcount=Page+inputsize
     str_NextPage="<a href="&QueURL&strcount&">"&Str_Next&"</a>&nbsp;"
else
     str_NextPage=Str_Next&"&nbsp;"
End if
'==================
if PageNo<>in_Rs.PageCount then
     strcount1=PageNo+1
     str_NextPage1="<a href="&QueURL&strcount1&">"&Str_Last&"</a>&nbsp;"
else
     str_NextPage1=Str_Last&"&nbsp;"
end if
'==================
     NextPage=str_NextPage&"&nbsp;"&str_NextPage1
End FunCtion
'===============================================
Private Function showNumber()'数字连接
Dim i,str_Num
For i=Page to Page+(inputsize-1)
     if i<=in_Rs.PageCount then
        if PageNo=i then
  str_Num=str_Num & "["&i&"]&nbsp;"
  else
        str_Num=str_Num & "<a href="& QueURL & i &">["&i&"]</a>&nbsp;"
  end if
     end if
Next
  showNumber=str_Num
End Function
'===============================================
Private Function MSG()
Dim str_MSG
str_MSG="当前:"&PageNo&"/"&in_Rs.Pagecount&"页 共"&in_Rs.recordcount&"条记录 "&inputsize&"条/每页"
MSG=str_MSG
End Function


'===============================================
Private Function QueURL()'取得当前文件名。各传送参数
Dim str_url,returnUrl,Get_url
  Str_url=Request.ServerVariables("URL")
     Str_url=split(str_url,"/")
     i=UBound(str_url)
     Get_url=str_url(i)
str_script=Request.ServerVariables("QUERY_STRING")
     If str_script="" Then
     returnUrl=Get_url & "?pageno="
     else
     returnUrl=Get_url & "?pageno="
     end if
QueURL=returnUrl
End Function
'===============================================

Private sub Show_Error(GetError)
if GetError<>"" then
response.write GetError
response.end
end if
end sub
'===============================================

Private Sub Class_Terminate  
       in_Rs.close
       Set in_Rs=nothing
End Sub
'===============================================

End class
%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值