生活的天平本不平衡,只有通过努力改变其偏向。

ASP分页类支持同一页面多分页

2005-06-17

‘*********************************************************************
‘名称:ASP分页类
‘功能:对数据库所有查询的记录集,进行分页,便于浏览.
‘说明:ASP分页类在网上已有很多了.这个分页类,除了且有一般的分页功能外,可以在同一个ASP页面,可以
‘     有多个分页.这本人写的第一个ASP类,有什么BUG希望给我写信.
‘作者:Lonkil
‘站点:www.vcfans.com
‘邮箱:vcfans (at) gmail (dot) com
‘日期:2005-6-16
‘*********************************************************************
‘*********************************************************************
下面对分页中比较重的成员函数作简要介绍.

‘类的处初化
Private sub Class_Initialize()
theUnit=”条”‘单位默认为“条”
thesizePages=20′默认每页20条
set Rs=server.CreateObject(“adodb.recordset”)
theParamName=”pages”‘默认的地址栏传参名。如果在同一个页面有多个分页,在别的分布中可以改此值.
ErrFlage=false
ErrString=”"
ListPageNum=10′列出分页的页数量,如:[1][2][3][4]…共10个
End sub

‘在分页时列出几项
Public Property Let ListNum(param)’列出分页数据,如[1][2][3][4]…
if cint(param)<1 or (not isnumeric(param)) then
ErrFlage=true
ErrString=”显示分页列表,不能是小于1整数!”
ShowErr()
end if
ListPageNum=param
End Property

‘整合SQL语句
Private function GetSQL()
if theFields=”" then
ErrFlage=true
ErrString=”所选的列名不能为空<br>”
ShowErr()
end if
if theTable=”" then
ErrFlage=true
ErrString=”操作的表名不能为空<br>”
ShowErr()
end if
if theFilters<>”" then
theFilters=” where “&theFilters&” ”
end if
if theOrderString<>”" then
theOrderString=” “&theOrderString
end if
if ErrFlage=false then
theSQL=”Select “&theFields&” from “&theTable&theFilters&theOrderString
end if
end function

‘取得当前文件的地址,并且过滤分页参数,将其保存到URL中。并且将当前页保存到CurPages
‘备注:URL,已经在未尾加上了’?'或’&’
‘此函数在本分页中比较中重要
Private function GetUrl()
dim QString,FilePath
dim strTemp
FilePath=request.ServerVariables(“URL”)
QString=request.ServerVariables(“QUERY_STRING”)
if QString<>”" then’后面参数不为空
if instr(QString,theParamName&”=”)<>0 and (not isnull(instr(QString,theParamName&”=”))) then’包含分页参数
strTemp=Mid(QString,instr(QString,theParamName&”=”))
if instr(strTemp,”&”)<>0 and (not isnull(instr(QString,theParamName&”=”))) then’分页参数后面还有参数
CurPages=clng(Mid(strTemp,(instr(strTemp,”=”)+1),(instr(strTemp,”&”)-instr(strTemp,”=”)-1)))’取得了此种情况下的当前页
if instr(QString,tehParamName)=1 then’分页参数前没有参数
URL=FilePath&”?”&replace(QString,theParamName&”=”&CurPages&”&”,”")
else
URL=FilePath&”?”&replace(QString,theParamName&”=”&CurPages&”&”,”")
end if
else
CurPages=clng(mid(strTemp,instr(strTemp,”=”)+1))
URL=FilePath&”?”&replace(QString,theParamName&”=”&CurPages,”")
end if
else
URL=FilePath&”?”&QString
CurPages=1
end if
else
URL=FilePath
CurPages=1
end if
if right(URL,4)=”.asp” then
URL=URL&”?”
else
if (right(url,1)<>”?”) and (right(url,1)<>”&”) then
URL=URL&”&”
end if
end if
end function

‘举例说明.
‘类的初使化
num=2′每页记录条数
set sp=new SplitPages’建立分页类对像
sp.conn=conn’传弟一个记录集
sp.ListFields=”VId,Name”‘筛选的数据列
sp.TableName=”test”‘表名
sp.Filters=”Typeid=3″‘筛选记录条件,去掉显示所有记录
sp.OrderString=”Order by Vid desc”‘排序方式
sp.Unit=”条记录”‘记录单位
sp.sizePages=num
sp.ListNum=10′列出当前页附近的几页
‘————————————-详细见类程序和示例!

  SplitPagesClass.rar (15.0 KiB, 544 hits)

作者:lonkil | 分类目录:本站原创编程开发 | 标签:

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>