欢迎光临
我们一直在努力

ASP通用分页类源码-ASP教程,ASP应用

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

<%

===================================================================

xdownpage asp版本

版本 1.00

code by zykj2000

email: zykj_2000@163.net

bbs: http://bbs.513soft.net

本程序可以免费使用、修改,希望我的程序能为您的工作带来方便

但请保留以上请息

程序特点

本程序主要是对数据分页的部分进行了封装,而数据显示部份完全由用户自定义,

支持url多个参数

使用说明

程序参数说明

papgesize 定义分页每一页的记录数

getrs 返回经过分页的recordset此属性只读

getconn 得到数据库连接

getsql 得到查询语句

程序方法说明

showpage 显示分页导航条,唯一的公用方法

===================================================================

const btn_first="<font face=""webdings"">9</font>" 定义第一页按钮显示样式

const btn_prev="<font face=""webdings"">3</font>" 定义前一页按钮显示样式

const btn_next="<font face=""webdings"">4</font>" 定义下一页按钮显示样式

const btn_last="<font face=""webdings"">:</font>" 定义最后一页按钮显示样式

const xd_align="center" 定义分页信息对齐方式

const xd_width="100%" 定义分页信息框大小

class xdownpage

private xd_pagecount,xd_conn,xd_rs,xd_sql,xd_pagesize,str_errors,int_curpage,str_url,int_totalpage,int_totalrecord,xd_surl

=================================================================

pagesize 属性

设置每一页的分页大小

=================================================================

public property let pagesize(int_pagesize)

if isnumeric(int_pagesize) then

xd_pagesize=clng(int_pagesize)

else

str_error=str_error & "pagesize的参数不正确"

showerror()

end if

end property

public property get pagesize

if xd_pagesize="" or (not(isnumeric(xd_pagesize))) then

pagesize=10

else

pagesize=xd_pagesize

end if

end property

=================================================================

getrs 属性

返回分页后的记录集

=================================================================

public property get getrs()

set xd_rs=server.createobject("adodb.recordset")

xd_rs.pagesize=pagesize

xd_rs.open xd_sql,xd_conn,1,1

if not(xd_rs.eof and xd_rs.bof) then

if int_curpage>xd_rs.pagecount then

int_curpage=xd_rs.pagecount

end if

xd_rs.absolutepage=int_curpage

end if

set getrs=xd_rs

end property

================================================================

getconn 得到数据库连接

================================================================

public property let getconn(obj_conn)

set xd_conn=obj_conn

end property

================================================================

getsql 得到查询语句

================================================================

public property let getsql(str_sql)

xd_sql=str_sql

end property

==================================================================

class_initialize 类的初始化

初始化当前页的值

==================================================================

private sub class_initialize

========================

设定一些参数的黙认值

========================

xd_pagesize=10 设定分页的默认值为10

========================

获取当前面的值

========================

if request("page")="" then

int_curpage=1

elseif not(isnumeric(request("page"))) then

int_curpage=1

elseif cint(trim(request("page")))<1 then

int_curpage=1

else

int_curpage=cint(trim(request("page")))

end if

end sub

====================================================================

showpage 创建分页导航条

有首页、前一页、下一页、末页、还有数字导航

====================================================================

public sub showpage()

dim str_tmp

xd_surl = geturl()

int_totalrecord=xd_rs.recordcount

if int_totalrecord<=0 then

str_error=str_error & "总记录数为零,请输入数据"

call showerror()

end if

if int_totalrecord="" then

int_totalpage=1

else

if int_totalrecord mod pagesize =0 then

int_totalpage = clng(int_totalrecord / xd_pagesize * -1)*-1

else

int_totalpage = clng(int_totalrecord / xd_pagesize * -1)*-1+1

end if

end if

if int_curpage>int_totalpage then

int_curpage=int_totalpage

end if

==================================================================

显示分页信息,各个模块根据自己要求更改显求位置

==================================================================

response.write ""

str_tmp=showfirstprv

response.write str_tmp

str_tmp=shownumbtn

response.write str_tmp

str_tmp=shownextlast

response.write str_tmp

str_tmp=showpageinfo

response.write str_tmp

response.write ""

end sub

====================================================================

showfirstprv 显示首页、前一页

====================================================================

private function showfirstprv()

dim str_tmp,int_prvpage

if int_curpage=1 then

str_tmp=btn_first&" "&btn_prev

else

int_prvpage=int_curpage-1

str_tmp="<a href="""&xd_surl & "1" & """>" & btn_first&"</a> <a href=""" & xd_surl & cstr(int_prvpage) & """>" & btn_prev&"</a>"

end if

showfirstprv=str_tmp

end function

====================================================================

shownextlast 下一页、末页

====================================================================

private function shownextlast()

dim str_tmp,int_nextpage

if int_curpage>=int_totalpage then

str_tmp=btn_next & " " & btn_last

else

int_nextpage=int_curpage+1

str_tmp="<a href=""" & xd_surl & cstr(int_nextpage) & """>" & btn_next&"</a> <a href="""& xd_surl & cstr(int_totalpage) & """>" & btn_last&"</a>"

end if

shownextlast=str_tmp

end function

====================================================================

shownumbtn 数字导航

====================================================================

private function shownumbtn()

dim i,str_tmp

for i=1 to int_totalpage

str_tmp=str_tmp & "[<a href=""" & xd_surl & cstr(i) & """>"&i&"</a>] "

next

shownumbtn=str_tmp

end function

====================================================================

showpageinfo 分页信息

更据要求自行修改

====================================================================

private function showpageinfo()

dim str_tmp

str_tmp="页次:"&int_curpage&"/"&int_totalpage&"页 共"&int_totalrecord&"条记录 "&xd_pagesize&"条/每页"

showpageinfo=str_tmp

end function

==================================================================

geturl 得到当前的url

更据url参数不同,获取不同的结果

==================================================================

private function geturl()

dim strurl,str_url,i,j,search_str,result_url

search_str="page="

strurl=request.servervariables("url")

strurl=split(strurl,"/")

i=ubound(strurl,1)

str_url=strurl(i)得到当前页文件名

str_params=trim(request.servervariables("query_string"))

if str_params="" then

result_url=str_url & "?page="

else

if instrrev(str_params,search_str)=0 then

result_url=str_url & "?" & str_params &"&page="

else

j=instrrev(str_params,search_str)-2

if j=-1 then

result_url=str_url & "?page="

else

str_params=left(str_params,j)

result_url=str_url & "?" & str_params &"&page="

end if

end if

end if

geturl=result_url

end function

====================================================================

设置 terminate 事件。

====================================================================

private sub class_terminate

xd_rs.close

set xd_rs=nothing

end sub

====================================================================

showerror 错误提示

====================================================================

private sub showerror()

if str_error <> "" then

response.write("" & str_error & "")

response.end

end if

end sub

end class

set conn = server.createobject("adodb.connection")

conn.open "driver={microsoft access driver (*.mdb)};dbq=" & server.mappath("pages.mdb")

#############类调用样例#################

创建对象

set mypage=new xdownpage

得到数据库连接

mypage.getconn=conn

sql语句

mypage.getsql="select * from [test] order by id asc"

设置每一页的记录条数据为5条

mypage.pagesize=5

返回recordset

set rs=mypage.getrs()

显示分页信息,这个方法可以,在set rs=mypage.getrs()以后,可在任意位置调用,可以调用多次

mypage.showpage()

显示数据

response.write("<br/>")

for i=1 to mypage.pagesize

这里就可以自定义显示方式了

if not rs.eof then

response.write rs(0) & "<br/>"

rs.movenext

else

exit for

end if

next

%>

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

相关推荐

  • 暂无文章