根据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