Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > asp函数/类库

超级asp大分页_我的类容我做主

来源:中文源码网    浏览:290 次    日期:2024-04-27 13:01:19
【下载文档:  超级asp大分页_我的类容我做主.txt 】


超级ASP大分页_我的类容我做主
超级ASP大分页_我的类容我做主 选择自 AppleBBS 的 Blog 关键字 超级ASP大分页_我的类容我做主 出处 <% '=================================================================== '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="9" '定义第一页按钮显示样式 Const Btn_Prev="3" '定义前一页按钮显示样式 Const Btn_Next="4" '定义下一页按钮显示样式 Const Btn_Last=":" '定义最后一页按钮显示样式 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-1Int_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="" & Btn_First&" " & Btn_Prev&"" 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="" & Btn_Next&" " & Btn_Last&"" 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 & "["&i&"] " 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 %> <% 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("
") for i=1 to hjmPage.GetCurPageNum '当前页的记录数目 '这里就可以自定义显示方式了 %>

相关内容