| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1927 人关注过本帖
标题:求asp分页代码
只看楼主 加入收藏
adwar
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2004-9-14
收藏
 问题点数:0 回复次数:5 
求asp分页代码

求asp分页代码

搜索更多相关主题的帖子: 页代码 asp 
2004-09-16 19:10
cime63
Rank: 1
等 级:新手上路
帖 子:167
专家分:0
注 册:2004-8-9
收藏
得分:0 

标题 ASP经典分页类 选择自 hrstudy 的 Blog 关键字 ASP经典分页类 出处 '===================================================================== 'XDOWNPAGE ASP版本 '版本 1.00 'Code by zykj2000 'Email: zykj_2000@163.net 'BBS: http://bbs.513soft.net '本程序可以免费使用、修改,希望我的程序能为您的工作带来方便 '但请保留以上请息 ' '程序特点 '本程序主要是对数据分页的部分进行了封装,而数据显示部份完全由用户自定义, '支持URL多个参数 ' '使用说明 '程序参数说明 'PapgeSize 定义分页每一页的记录数 'GetRS 返回经过分页的Recordset此属性只读 'GetConn 得到数据库连接 'GetSQL 得到查询语句 '程序方法说明 'ShowPage 显示分页导航条,唯一的公用方法 ' '例: ' ' '包含文件 ' ' Set mypage=new xdownpage '创建对象 ' mypage.getconn=conn '得到数据库连接 ' mypage.getsql="select * from productinfo order by id asc" ' mypage.pagesize=5 '设置每一页的记录条数据为5条 ' set rs=mypage.getrs() '返回Recordset ' mypage.showpage() '显示分页信息,这个方法可以,在set rs=mypage.getrs()以后 ' 任意位置调用,可以调用多次 ' for i=1 to mypage.pagesize '接下来的操作就和操作一个普通Recordset对象一样操作 ' if not rs.eof then '这个标记是为了防止最后一页的溢出 ' response.write rs(0) & " " '这里就可以自定义显示方式了 ' rs.movenext ' else ' exit for ' end if ' next ' '=====================================================================

Const Btn_First="9" '定义第一页按钮显示样式 Const Btn_Prev="3" '定义前一页按钮显示样式 Const Btn_Next="4" '定义下一页按钮显示样式 Const Btn_Last=":" '定义最后一页按钮显示样式 Const XD_Align="center" '定义分页信息对齐方式 Const XD_Width="100%" '定义分页信息框大小 Const XD_Height="20" Class Xdownpage Private XD_PageCount,XD_Conn,XD_Rs,XD_SQL,XD_PageSize,Str_errors,int_curpage,str_URL,int_totalPage,int_totalRecord

'================================================================= '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 int_totalRecord=XD_RS.RecordCount If int_totalRecord<=0 Then str_error=str_error & "总记录数为零,请输入数据" Call ShowError() End If If int_totalRecord int_TotalPage=1 Else If int_totalRecord mod PageSize =0 Then int_TotalPage = Int(int_TotalRecord / XD_PageSize * -1)*-1 Else int_TotalPage = Int((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 " " ShowGoto 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 数字导航 ' ' '==================================================================== 'Private Function showNumBtn() ' Dim i,str_tmp ' For i=1 to int_totalpage ' str_tmp=str_tmp & "["&i&"] " ' Next ' showNumBtn=str_tmp ' 'End Function '==================================================================== 'ShowNumBtn 修改后的数字导航 ' '==================================================================== Function showNumBtn() Dim i,str_tmp,end_page,start_page if int_curpage>4 then if int_curpage+2 start_page=int_curpage-2 end_page=int_curpage+2 else start_page=int_totalpage-4 end_page=int_totalpage end if else start_page=1 if int_totalpage>5 then end_page=5 else end_page=int_totalpage end if end if For i=start_page to end_page str_tmp=str_tmp & " ["&i&"] " Next showNumBtn=str_tmp End Function

'==================================================================== 'ShowGoto 页面跳转 ' ' '==================================================================== Private Function ShowGoto() Dim M_item '======================================================== '将返回的Url参数逐个的写入隐藏域中,以便与参数继续传递 '======================================================== For Each M_item In Request.QueryString If InStr("page",M_Item)=0 Then '从参数中除去 "page" 的值 Response.Write "" End If Next '======================================================== response.write " 转到第:" response.write " 页 " End Function

'==================================================================== 'ShowPageInfo 分页信息 '更据要求自行修改 ' '==================================================================== Private Function ShowPageInfo() Dim str_tmp str_tmp=" [页次:"&int_curpage&"/"&int_totalpage&"页] [共"&int_totalrecord&"条] ["&XD_PageSize&"条/页]" ShowPageInfo=str_tmp End Function

'==================================================================== '修改后的获取当前Url参数的函数 'Codeing by Redsun '==================================================================== Private Function GetUrl() Dim ScriptAddress, M_ItemUrl, M_item ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))&"?"'取得当前地址 If (Request.QueryString <> "") Then M_ItemUrl = "" For Each M_item In Request.QueryString If InStr("page",M_Item)=0 Then M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&" End If Next ScriptAddress = ScriptAddress & M_ItemUrl'取得带参数地址 End If GetUrl = ScriptAddress & "page=" 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(" " & SW_Error & "") Response.End End If End Sub

End class


2004-09-16 22:06
cime63
Rank: 1
等 级:新手上路
帖 子:167
专家分:0
注 册:2004-8-9
收藏
得分:0 

<% '************************************************************************************ '*********************************asp分页类****************************************** '******************在50,000条记录下测试过,速度比ado的那个要快多了******************* '************************************************************************************ '具体用法 'Set conn=Server.CreateObject("ADODB.Connection") 'conn.open "DRIVER={SQL Server};SERVER=(local);UID=sa;PWD=1230;DATABASE=Music" 'set rs = mp.Execute("select * from MusicList",conn,29) 'while not rs.eof ' response.write rs2("MusicName")&"<br>" ' rs2.MoveNext 'wend 'mp.pageDispaly() '************************************************************************************ Class MyPage private MyPage_Conn,MyPage_StrSql,MyPage_TotalStrSql,MyPage_RS,MyPage_TotalRS private MyPage_PageSize private MyPage_PageAbsolute,MyPage_PageTotal,MyPage_RecordTotal private MyPage_Url public property let conn(strConn) set MyPage_Conn = strConn end property

public property let PageSize(intPageSize) MyPage_PageSize = Cint(intPageSize) end property

public function PageExecute(strSql) MyPage_PageAbsolute = MyPage_PageAbsoluteRequest() MyPage_TotalStrSql = FormatMyPage_TotalStrSql(strSql) set MyPage_TotalRS = MyPage_Conn.execute(MyPage_TotalStrSql) MyPage_RecordTotal = MyPage_TotalRS("total") MyPage_PageTotal = Cint(MyPage_RecordTotal/MyPage_PageSize) MyPage_StrSql = FormatMyPage_StrSql(strSql) set MyPage_RS = MyPage_Conn.execute(MyPage_StrSql) dim i i = 0 while not MyPage_RS.eof and i<(MyPage_PageAbsolute-1)*MyPage_PageSize i = i + 1 MyPage_RS.MoveNext wend set PageExecute = MyPage_RS end function

public function Execute(strSql,strConn,intPageSize) conn = strConn PageSize = intPageSize set Execute = PageExecute(strSql) end function

public function pageDispaly() MyPage_Url = ReadMyPage_Url firstPageTag = "<font face=webdings>9</font>" '|<< LastPageTag = "<font face=webdings>:</font>" '>>| previewPageTag = "<font face=webdings>7</font>" '<< nextPageTag = "<font face=webdings>8</font>" '>> dim strAnd if instr(MyPage_Url,"?")=0 then strAnd = "?" else strAnd = "&" end if response.write "<table width=100% border=0 cellspacing=0 cellpadding=0>" response.write "<tr>" response.write "<td align=left>" response.write "页次:"&MyPage_PageAbsolute&"/"&MyPage_PageTotal&"页&nbsp" response.write "主题数:"&MyPage_RecordTotal response.write "</td>" response.write "<td align=right>" response.write "分页:" if MyPage_PageAbsolute>10 then response.write "<a href='"&MyPage_Url&strAnd&"MyPage_PageNo=1'>"&firstPageTag&"</a>" response.write "<a

href='"&MyPage_Url&strAnd&"MyPage_PageNo="&(MyPage_PageAbsolute-10)&"'>"&previewPageTag&"</a>" else response.write firstPageTag response.write previewPageTag end if response.write "&nbsp" dim CurrentStartPage,i i = 1 CurrentStartPage=(Cint(MyPage_PageAbsolute)\10)*10+1 if Cint(MyPage_PageAbsolute) mod 10=0 then CurrentStartPage = CurrentStartPage - 10 end if while i<11 and CurrentStartPage<MyPage_PageTotal+1 if CurrentStartPage < 10 then FormatCurrentStartPage = "0" & CurrentStartPage else FormatCurrentStartPage = CurrentStartPage end if response.write "<a

href='"&MyPage_Url&strAnd&"MyPage_PageNo="&CurrentStartPage&"'>"&FormatCurrentStartPage&"</a>&nbsp" i = i + 1 CurrentStartPage = CurrentStartPage + 1 wend if MyPage_PageAbsolute<(MyPage_PageTotal-10) then response.write "<a

href='"&MyPage_Url&strAnd&"MyPage_PageNo="&(MyPage_PageAbsolute+10)&"'>"&nextPageTag&"</a>" response.write "<a

href='"&MyPage_Url&strAnd&"MyPage_PageNo="&MyPage_PageTotal&"'>"&LastPageTag&"</a>" else response.write nextPageTag response.write LastPageTag end if response.write "" response.write "</td>" response.write "</tr>" response.write "</table>" end function

public function GetPageNo() GetPageNo = cint(MyPage_PageAbsolute) end function

public function GetPageCount() GetPageCount = cint(MyPage_PageTotal) end function

public function GetPageNoName() GetPageNoName = "MyPage_PageNo" end function

public function GetPageSize() GetPageSize = MyPage_PageSize end function

public function GetRecordTotal() GetRecordTotal = MyPage_RecordTotal end function

private function FormatMyPage_TotalStrSql(strSql) FormatMyPage_TotalStrSql = "select count(*) as total " FormatMyPage_TotalStrSql = FormatMyPage_TotalStrSql & Mid(strSql,instr(strSql,"from")) FormatMyPage_TotalStrSql = Mid(FormatMyPage_TotalStrSql,1,instr(FormatMyPage_TotalStrSql&"order by","order

by")-1) end function

private function FormatMyPage_StrSql(strSql) FormatMyPage_StrSql = replace(strSql,"select","select top "&(MyPage_PageAbsolute*Cint(MyPage_PageSize))) end function

private function MyPage_PageAbsoluteRequest() if request("MyPage_PageNo")="" then MyPage_PageAbsoluteRequest = 1 else if IsNumeric(request("MyPage_PageNo")) then MyPage_PageAbsoluteRequest = request("MyPage_PageNo") else MyPage_PageAbsoluteRequest = 1 end if end if end function

private function ReadMyPage_Url() ReadMyPage_Url = Request.ServerVariables("URL") if Request.QueryString<>"" then ReadMyPage_Url = ReadMyPage_Url & "?" & Request.QueryString end if set re = new RegExp re.Pattern = "[&|?]MyPage_PageNo=\d+?" re.IgnoreCase = true re.multiLine = true re.global = true Set Matches = re.Execute(ReadMyPage_Url) For Each Match in Matches tmpMatch = Match.Value ReadMyPage_Url = replace(ReadMyPage_Url,tmpMatch,"") next end function end Class %>


2004-09-16 22:10
cime63
Rank: 1
等 级:新手上路
帖 子:167
专家分:0
注 册:2004-8-9
收藏
得分:0 

介绍几个分页类给你,楼主。今天和同学喝多了点,不好意思啊。嘻嘻


2004-09-16 22:11
adwar
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2004-9-14
收藏
得分:0 

谢谢你的提供,有空和你联系

2004-09-17 15:18
cime63
Rank: 1
等 级:新手上路
帖 子:167
专家分:0
注 册:2004-8-9
收藏
得分:0 

可惜这些类不是我写的。我的QQ是121606843

ASP初学,大家常联系

一起进步


2004-09-17 16:41
快速回复:求asp分页代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020043 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved