欢迎光临
我们一直在努力

分页类-ASP教程,ASP应用

建站超值云服务器,限时71元/月

根据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 定义向上和向下翻的变量

———————–首页————————-

if currentpage>1 then

firstlink = "<a href=" & url & pageparam & "1>首页</a>"

prevlink = "<a href=" & url & pageparam & cstr(currentpage-1) & ">上一页</a>"

else

firstlink = "首页"

prevlink = "上一页"

end if

————下一页—————-

if currentpage<pgcount then

nextlink = "<a href=" & url & pageparam & cstr(currentpage+1) & ">下一页</a>"

lastlink = "<a href=" & url & pageparam & pgcount & ">尾页</a>"

else

nextlink = "下一页"

lastlink = "尾页"

end if

pageinfomation = firstlink & seperator & prevlink & seperator & nextlink & seperator & lastlink & seperator & "每页" & cstr(int_pagesize) & "条记录" & seperator & "共" & pgcount & "页" & seperator & "目前第" & currentpage & "页" & seperator

response.write("<tr><td align=center>")

response.write("<table width=100% border=1 cellpadding=2 cellspacing=2 bordercolor=#999999>")

—————设置表头—————–

response.write("<tr bgcolor=" & str_titlecolor & ">")

dim i

for i=0 to fieldcount -1

response.write("<td align=center width=" & arr_fieldwidth(i) & "><font style=font-size:14px;><b>" & arr_fieldname(i) & "</b></font></td>")

next

response.write("</tr>")

———————输出内容———————————

i=0

while (not obj_recordset.eof) and i<int_pagesize

dim cursor

response.write("<tr>")

for cursor = 0 to fieldcount -1

response.write("<td align=center>" & obj_recordset(arr_field(cursor)) & "</td>")

next

response.write("</tr>")

i=i+1

obj_recordset.movenext

wend

————————输出分页条————————————

response.write("<tr><td align=right colspan=" & cstr(fieldcount) & ">" & pageinfomation & "</td></tr>")

response.write("</table></td></tr></table>")

end if

end sub

———-检查参数是否正确—————

private sub check()

if ubound(arr_field)<>ubound(arr_fieldname) then

str_error="fields数组和fieldname数组维数必须相同"

end if

if obj_recordset=empty then

str_error="数据源不能为空,请设置datasource属性"

end if

if int_pagesize="" then

str_error="数据源不能为空"

end if

showlasterror

end sub

end class

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 分页类-ASP教程,ASP应用
分享到: 更多 (0)