[类] 分页类[1]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 fuxingboy 的 blog

根据ado纪录集自动生成列表和分页,需要先生成recordset:rs_grid
<%
'===========================================================
'分页类,大体思想由.net的datagrid的使用方式而来
'功能:自动生成datagrid列表头和内容,以及分页栏
'根据网友bubuy (澎湃 nomoneytobuy)得分页函数修改成类
'使用示例:
'dim dg
'dim url
'dim fld(2)
'dim fldname(2)
'dim fldwidth(2)
'fld(0) = "id"
'fld(1) = "title"
'fld(2) = "input_date"
'fldname(0) = "编号"
'fldname(1) = "标题"
'fldname(2) = "录入日期"
'fldwidth(0) = "10%"
'fldwidth(1) = "60%"
'fldwidth(2) = "30%"
'set dg = new datagrid
'dg.datasource = rs_grid
'dg.titlecolor = "#dce19d"
'dg.pagesize = 1
'dg.fields = fld
'dg.fieldsname = fldname
'dg.fieldwidth = fldwidth
'url = request.servervariables("url") & "?param=testparameter"//存在原有参数的情况
'dg.url = url
'dg.generate()
'=============designed by windancer 2003.10.17===============
class datagrid
private obj_recordset ' recordset
private int_pagesize ' 每页纪录数
'两个数组保存数据库字段名和中文名称
private arr_field ' 数据库字段
private arr_fieldname ' 字段显示名称()
private arr_fieldwidth ' 字段显示宽度
private str_titlecolor ' 表头颜色#efffce
private str_url '请求的url
private str_error ' 出错信息

private sub class_initialize()
int_pagesize = 10
str_titlecolor = "#ffffff"
str_error = ""
end sub
'===============================================================
'属性信息
'================================================================
'-----------------------------------
'数据源,暂时只支持recordset
'-----------------------------------
public property let datasource(obj)
set obj_recordset = obj
end property

public property let pagesize(intvalue)
int_pagesize = intvalue
end property

public property get pagesize
pagesize= int_categoryid
end property

public property let fields(arr)
arr_field = arr
end property

public property get fields
fields= arr_field
end property

public property let fieldsname(arr)
arr_fieldname = arr
end property

public property get fieldsname
fieldsname= arr_fieldname
end property

public property let fieldwidth(arr)
arr_fieldwidth = arr
end property

public property get fieldwidth
fieldwidth= arr_fieldwidth
end property

public property let titlecolor(strvalue)
str_titlecolor = strvalue
end property

public property get titlecolor
titlecolor= str_titlecolor
end property
'-----------------------------------------------------
'这个属性是为了保存url路径
'如果当前路径带有参数,那么就用&page=x,否则就用?page=x
'------------------------------------------------------
public property let url(strvalue)
str_url = strvalue
end property

public property get url
url= str_url
end property

'================================================================
'方法
'================================================================
'----------------------------------------------------------------
'显示当前错误
'----------------------------------------------------------------
private sub showlasterror()
response.write(str_error)
response.end()
end sub
'----------------------------------------------------------------
'generate()
'利用ado分页
'-----------------------------------------------------------------
public sub generate()
'----检查参数--------------------------
check
'---------变量声明-----------------------------------
dim fieldcount '显示字段
fieldcount = ubound(arr_field) + 1
dim currentpage '当前页
dim pgcount '总页数
dim reccount '记录数,本来用rs.recordcount可以取到,保存下来效率会比较高
dim hasotherparam 'url是否包含其他参数
dim pageparam '当前分页url参数
dim pageinfomation '当前分页状态信息
dim seperator '设置分隔符
seperator = "  "
'-------------处理url参数---------------------------
if instr(str_url,"?")>0 then
hasotherparam = true
pageparam = "&page="
else
hasotherparam = false
pageparam = "?page="
end if
'----------获取当前页--------------------------------
currentpage = request.querystring("page")
if currentpage="" then
currentpage=1
else
currentpage=cint(currentpage)
end if
'-----------处理数据源------------------------------
obj_recordset.pagesize = int_pagesize
reccount = obj_recordset.recordcount
pgcount = obj_recordset.pagecount
if obj_recordset.eof then
response.write("<center><font stlye='font-size:14px;' color='#ff0000'>对不起,没有记录!</font></center>")
else
'-----------处理ado分页----------------------------
if currentpage < 1 then
currentpage = 1
else
if currentpage>pgcount then
currentpage = pgcount
end if
end if
obj_recordset.absolutepage = currentpage

response.write("<table width=100% border='0' cellpadding='0' cellspacing='0' style='font-size:12px;'>")
'---------------翻页链接-----------------------------
dim firstlink,prevlink,nextlink,lastlink '定义向上和向下翻的变量

本文关键:分页类
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top