一个分页的类
发表于:2007-06-30来源:作者:点击数:
标签:
% ‘’------------------------------------------- ‘’ 接口: ‘’ 属性: ‘’ a、tip:项目提示(如,“篇文章”); ‘’ b、tablewidth:跳转页导航宽度 ‘’ 方法: ‘’ a、SetRsObj()方法:设置ADODB.RECORDSET对象; ‘’ b、ControlPages()
<%
‘’-------------------------------------------
‘’ 接口:
‘’ 属性:
‘’ a、tip:项目提示(如,“篇文章”);
‘’ b、tablewidth:跳转页导航宽度
‘’ 方法:
‘’ a、SetRsObj()方法:设置ADODB.RECORDSET对象;
‘’ b、ControlPages()方法:显示跳转页导航(“上一页”、“下一页”……)
‘’ c、SetParams()方法:设置参数数组
‘’ 范例:
‘’ dim params(1,1)
‘’ params(0,0) = "query" : params(0,1) = request("query")
‘’ params(1,0) = "keyword" : params(1,1) = request("keyword")
‘’ 该数组主要传递查询关键字(如字段关键字、时间等),第一维是参数名称,第二维是参数值:如下http://…….asp?topage=2&query=yes&keyword=a
‘’
‘’ set PageCtrl = new CPageCtrl
‘’ PageCtrl.SetRsObj (RS) ‘’设置ADODB.RECORDSET对象,其中RS是已建立好的ADODB.RECORDSET,即所要控制的记录集
‘’ PageCtrl.tip = "篇文章"
‘’ PageCtrl.tablewidth = "100%"
‘’ PageCtrl.SetParams params
‘’ PageCtrl.DimPage (15) ‘’分页定义,每页15条记录
‘’ PageCtrl.ControlPages() ‘’显示跳转页导航
‘’-------------------------------------------
class CPageCtrl
public tip, tablewidth
private setobjflag, rsobj, pages, record, setpara
msflag, current, topage
dim params()
‘’----------------------------------
private sub class_initialize()
tablewidth = "100%"
end sub
‘’---------------------------------
public function SetRsObj(obj)
set rsobj = obj
setobjflage = true
end function
‘’----------------------------------
private function chksetobj()
if setobjflage <> true then response.End()
end function
‘’----------------------------------
public function DimPage(psize) ‘’分页定义
dim topages
topage = request("topage")
if not rsobj.eof then
if not isempty(psize) then
rsobj.pagesize = cint(psize) ‘’定义每页显示数目
else
rsobj.pagesize = rsobj.recordcount
end if
pages = rsobj.pagecount
record = rsobj.recordcount
if topage <> empty then
topages = CInt(topage)
if topage <= 1 then
rsobj.absolutepage = 1
elseif topages >= pages then
rsobj.absolutepage = pages
else
rsobj.absolutepage = topages
end if
end if
current = rsobj.absolutepage
end if
end function
‘’----------------------------------
public function SetParams(arrParams())
params = arrParams
setparamsflag = true
end function
‘’----------------------------------
public function controlpages()
dim url
url = "http://" & request.ServerVariables("HTTP_HOST") & request.ServerVariables("URL")
if setparamsflag = true then
row = ubound(params,1)
col = ubound(params,2)
if col <> 1 then
exit function
end if
for i = 0 to row
if params(i,0) <> empty then
condition = condition & "&" & params(i,0) & "=" & params(i,1)
‘’生成参数
end if
next
end if
response.write "<table width=‘’" & tablewidth & "‘’ border=‘’0‘’ cellspacing=‘’0‘’ cellpadding=‘’0‘’>"
response.write "<form action=‘’" & url & "‘’ method=‘’post‘’>"
response.write "<tr> "
response.write "<
td height=‘’20‘’> 目前共有 <font color=‘’red‘’><b>" & record & "</b></font> "& tip & " 当前分页状况 <font color=‘’red‘’><b>" & current & "/" & pages & "</b></font></td>"
if current <> 1 then
response.write "<td width=‘’40‘’ align=‘’center‘’ height=‘’20‘’>"
response.write "<a href=‘’" & url & "?topage=1" & condition & "‘’>首 页</a>"
response.write "</td>"
response.write "<td width=‘’44‘’ align=‘’center‘’ height=‘’20‘’>"
response.write "<a href=‘’" & url & "?topage=" & current-1 & condition & "‘’>上一页</a>"
response.write "</td>"
else
response.write "<td width=‘’40‘’ align=‘’center‘’ height=‘’20‘’>"
response.write "<font color=‘’#999999‘’>首 页</font>"
response.write "</td>"
response.write "<td width=‘’44‘’ align=‘’center‘’ height=‘’20‘’>"
response.write "<font color=‘’#999999‘’>上一页</font>"
response.write "</td>"
end if
if current <> pages then
response.write "<td width=‘’44‘’ align=‘’center‘’ height=‘’20‘’>"
response.write "<a href=‘’" & url & "?topage=" & current+1 & condition & "‘’>下一页</a>"
response.write "</td>"
response.write "<td width=‘’40‘’ align=‘’center‘’ height=‘’20‘’>"
response.write "<a href=‘’" & url & "?topage=" & pages & condition & "‘’>尾 页</a>"
response.write "</td>"
else
response.write "<td width=‘’44‘’ align=‘’center‘’ height=‘’20‘’>"
response.write "<font color=‘’#999999‘’>下一页</font>"
response.write "</td>"
response.write "<td width=‘’40‘’ align=‘’center‘’ height=‘’20‘’>"
response.write "<font color=‘’#999999‘’>尾 页</font>"
response.write "</td>"
end if
response.write "<td>"
response.write "<input type=‘’text‘’ name=‘’topage‘’ size=‘’4‘’ style=‘’BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #a0a0a0 1px solid; BORDER-LEFT: #a0a0a0 1px solid; BORDER-RIGHT: #a0a0a0 1px solid; BORDER-TOP: #a0a0a0 1px solid; FONT-SIZE: 12px‘’>"
response.write "</td>"
response.write "</tr>"
response.write "</form>"
response.write "</table>"
end function
end class
%>
原文转自:http://www.ltesting.net