欢迎光临
我们一直在努力

超级ASP大分页_我的类容我做主-ASP教程,ASP应用

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

<%

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

showmorepage asp版本

version huangjm1.00

code by maomao

create date 2004-09-28

qq:5144707

http://blog.csdn.net/maomaoysq

write for my lover:huangjm 本程序可以免费使用、修改,但请保留以上信息

function

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

支持url多个参数:http://www.***.com/***.asp?aa=1&page=9&bb=2

paramers:

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

getcurpagenum 返回当前页的记录集数目此属性只读

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

getconn 得到数据库连接

getsql 得到查询语句

interface of class

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

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

创建对象

set hjmpage=new showmorepage

得到数据库连接

hjmpage.getconn=conn

sql语句

hjmpage.getsql="select * from shop_books where newsbook=1 order by bookid desc"

设置每一页的记录条数据为20条,默认显示10条

hjmpage.pagesize=20

显示分页信息,可在任意位置调用,可以调用多次

hjmpage.showpage()

set rs=hjmpage.getrs() 返回recordset

显示数据开始

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

for i=1 to hjmpage.getcurpagenum 当前页的记录数目

response.write left(trim(rs("bookname")),13)&"…."

rs.movenext

next

显示数据结束

set hjmpage=nothing

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

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

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 showmorepage

private obj_conn,obj_rs,str_sql,int_pagesize,str_errors,int_curpage,str_url,int_totalpage,int_totalrecord

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

pagesize 属性

设置每一页的分页大小

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

public property let pagesize(intvalue)

if isnumeric(intvalue) then

int_pagesize=clng(intvalue)

else

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

showerror()

end if

end property

public property get pagesize

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

pagesize=10

else

pagesize=int_pagesize

end if

end property

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

getrs 属性

返回分页后的记录集

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

public property get getrs()

if int_totalrecord= 0 then call getpage()

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

if int_curpage<>1 then

if int_curpage-1<int_totalpage then

obj_rs.move (int_curpage-1)*pagesize

dim bookmark

bookmark=obj_rs.bookmark

else

int_curpage=1

end if

end if

end if

set getrs=obj_rs

end property

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

getcurpagenum 属性

返回当前页的记录集数目

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

public property get getcurpagenum()

dim int_pagenum

int_pagenum = int_pagesize

if int_totalrecord= 0 then call getpage()

if int_curpage>int_totalpage then

int_curpage=int_totalpage

int_pagenum = int_totalrecord-(int_totalpage-1)*int_pagesize

elseif int_curpage=int_totalpage then

int_pagenum = int_totalrecord-(int_totalpage-1)*int_pagesize

end if

getcurpagenum = int_pagenum

end property

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

getconn 得到数据库连接

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

public property let getconn(sconn)

set obj_conn=sconn

end property

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

getsql 得到查询语句

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

public property let getsql(svalue)

str_sql=svalue

end property

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

class_initialize 类的初始化

初始化当前页的值

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

private sub class_initialize

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

设定一些参数的黙认值

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

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

int_totalrecord= 0

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

获取当前面的值

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

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

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

openrs 打开数据集

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

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

private sub openrs()

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

obj_rs.open str_sql,obj_conn,1,1

end sub

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

getpage 创建分页导航条

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

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

private sub getpage()

if typename(obj_rs)<>"object" then call openrs()

int_totalrecord=obj_rs.recordcount

if int_totalrecord<=0 then

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

call showerror()

end if

if int_totalrecord mod pagesize =0 then

int_totalpage = int_totalrecord \ int_pagesize

else

int_totalpage = int_totalrecord \ int_pagesize+1

end if

if int_curpage>int_totalpage then

int_curpage=int_totalpage

end if

end sub

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

showpage 创建分页导航条

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

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

public sub showpage()

dim str_tmp

str_url = geturl()

if int_totalrecord= 0 then call getpage()

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

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

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

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="""&str_url & "1" & """>" & btn_first&"</a> <a href=""" & str_url & 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=""" & str_url & cstr(int_nextpage) & """>" & btn_next&"</a> <a href="""& str_url & cstr(int_totalpage) & """>" & btn_last&"</a>"

end if

shownextlast=str_tmp

end function

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

shownumbtn 数字导航

每次显示10页

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

private function shownumbtn()

dim i,str_tmp,m,n

m = int_curpage – 4

n = int_totalpage

if n>1 then

for i = 1 to 10

if m < 1 then m = 1

if m > n then

exit for

end if

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

m = m + 1

next

end if

shownumbtn=str_tmp

end function

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

showpageinfo 分页信息

更据要求自行修改

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

private function showpageinfo()

dim str_tmp

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

showpageinfo=str_tmp

end function

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

geturl 得到当前的url

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

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

private function geturl()

dim strurl,tmp_url,i,j,search_str,result_url

search_str="page="

strurl=request.servervariables("url")

strurl=split(strurl,"/")

i=ubound(strurl,1)

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

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

if str_params="" then

result_url=tmp_url & "?page="

else

if instrrev(str_params,search_str)=0 then

result_url=tmp_url & "?" & str_params &"&page="

else

j=instrrev(str_params,search_str)-2

if j=-1 then

result_url=tmp_url & "?page="

else

str_lparams=left(str_params,j)

str_rparams=right(str_params,len(str_params)-j-1)

if instr(str_rparams,"&")<>0 then

str_rparams=right(str_rparams,len(str_rparams)-instr(str_rparams,"&")+1)

else

str_rparams = ""

end if

result_url=tmp_url & "?" & str_lparams&str_rparams&"&page="

end if

end if

end if

geturl=result_url

end function

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

设置 terminate 事件。

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

private sub class_terminate

obj_rs.close

set obj_rs=nothing

obj_conn.close

set obj_conn = nothing

end sub

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

showerror 错误提示

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

private sub showerror()

if str_errors <> "" then

response.write("" & str_errors & "")

response.end

end if

end sub

end class

%>

<!–#include file="include/function.asp"–>

<%

dim conn

call dbconnect()

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

创建对象

set hjmpage=new showmorepage

得到数据库连接

hjmpage.getconn=conn

sql语句

hjmpage.getsql="select top 6 * from shop_books where newsbook=1 order by bookid desc"

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

hjmpage.pagesize=2

set rs=hjmpage.getrs() 返回recordset

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

hjmpage.showpage()

显示数据

response.write("<br/>")

for i=1 to hjmpage.getcurpagenum 当前页的记录数目

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

%>

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

相关推荐

  • 暂无文章