|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
[分享]利用高手编的分页程序加了个跳转分页,使用比较简单!
[分享]利用高手编的分页程序加了个跳转分页,使用比较简单!
效果如下:
首页 前一页[1] [2] [3] [4] [5] 下一页 尾页 当前页次:1/53页 每页15条记录 共777条记录 跳转到第_页
非常感谢论坛上各位朋友的支持与帮助
有使用范例
<%
'===================================================================
'XDOWNPAGE ASP版本
'版本 1.00
'Code by zykj2000
'Email: [email]zykj_2000@163.net[/email]
'BBS: http://bbs.513soft.net
'本程序可以免费使用、修改,希望我的程序能为您的工作带来方便
'但请保留以上请息
'
'程序特点
'本程序主要是对数据分页的部分进行了封装,而数据显示部份完全由用户自定义,
'支持URL多个参数
'
'使用说明
'程序参数说明
'PapgeSize 定义分页每一页的记录数
'GetRS 返回经过分页的Recordset此属性只读
'GetConn 得到数据库连接
'GetSQL 得到查询语句
'程序方法说明
'ShowPage 显示分页导航条,唯一的公用方法
'
'===================================================================
Const Btn_First="首页" '定义第一页按钮显示样式
Const Btn_Prev="前一页" '定义前一页按钮显示样式
Const Btn_Next="下一页" '定义下一页按钮显示样式
Const Btn_Last="尾页" '定义最后一页按钮显示样式
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=15 '设定分页的默认值为20
'========================
'获取当前面的值
'========================
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
str_tmp=ShowJumpPage
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=int_curpage to (int_curpage+4)
'For i=1 to int_totalpage
str_tmp=str_tmp & "[<a href=""" & XD_sURL & CStr(i) & """>"&i&"</a>] "
Next
showNumBtn=str_tmp
End Function
'====================================================================
'Showjumppage 跳转分页
'
'
'====================================================================
Private Function ShowJumpPage()
dim i,str_tmp
'显示跳转菜单开始
str_tmp=" 跳转到第<select name='select' onChange='javascript:window.location.href=(this.options[this.selectedIndex].value);'>"
for i=1 to int_totalpage
str_tmp=str_tmp & "<option value=""" & XD_sURL & CStr(i) & """>"&i&"</option>"
next
str_tmp=str_tmp &"</select>页"
ShowJumpPage=str_tmp
'显示跳转菜单结束
End Function
'====================================================================
'ShowPageInfo 分页信息
'更据要求自行修改
'
'====================================================================
Private Function ShowPageInfo()
Dim str_tmp
str_tmp=" 当前页次:<font color=red>"&int_curpage&"</font>/"&int_totalpage&"页 每页"&XD_PageSize&"条记录 共"&int_totalrecord&"条记录"
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
%> |
垃圾
不是什么好东西
太烦琐了
可以简练点的
::
说话太直,不要生气,哈哈 |
各人爱好吧,这个是我在网上找的,搞了很久才可以正常使用的,很高兴
希望可以对有需要的朋友有帮助 |
做个压缩包上传上来就好了! |
上面的分页数字导航有点问题,就是我一共有64页,但是我点到63页的时候,会出现68页,各位老大帮我想想办法啊 |
我用乔客分页,不过我把他改成适用于dreamweaver的样子。和我一样初学的可以看看
http://www.zxzs-china.com/amu/web/datacontent.asp?order=165
[code]
1。利用dreamweaver生成一部分代码(绑定记录集那一步)
2。确定记录集不为空的情况下在记录集下面插入如下代码:
<%
dim rssum,maxpage,thepages,viewpage,i,j,pageurl
pageurl="page.asp?"
rssum=conn.recordcount '总数
maxpage=10 '每页数
if rssum=-1 then
rssum=0
While (Not conn.EOF)
rssum = rssum + 1
conn.MoveNext
Wend
end if
i=0
viewpage=trim(request("page"))
conn.movefirst
if rssum mod maxpage > 0 then
thepages=rssum\maxpage+1
else
thepages=rssum\maxpage
end if
if viewpage="" or isnull(viewpage) or not(isnumeric(viewpage)) then
viewpage=1
elseif cint(viewpage)<1 then
viewpage=1
else
if cint(viewpage)>thepages then
viewpage=1
end if
end if
While (Not i=(viewpage-1)*maxpage)
conn.MoveNext
i=i+1
Wend
%>
3。如下代码为资料统计:
现在有<font color=#ff0000><% =rssum %></font>条
/ 每页<font color=#ff0000><% =maxpage %></font>条
/ 共<font color=#ff0000><% =thepages %></font>页
/ 这是第<font color=#ff0000><% =viewpage %></font>页
4。如下代码:
<%
i=1
'if viewpage<>"1" then
' rs.move (viewpage-1)*maxpage
'end if
for i=1 to maxpage
if conn.eof then exit for
%>
和
<%conn.movenext
next%>
用来循环显示
4。如下代码为功能强大的分页:
<%
pagecute_fun maxpage,thepages,viewpage,pageurl
function pagecute_fun(maxpage,thepages,viewpage,pageurl)
dim pn,pi,page_num,pp
pp=6
pi=1
if thepages mod pp > 0 then
page_num=thepages\pp+1
else
page_num=thepages\pp
end if
if viewpage mod pp > 0 then
pn=viewpage\pp+1
else
pn=viewpage\pp
end if
if cint(page_num)>1 and cint(pn)<>1 then
response.write(" <a class=menu href='"& pageurl &"page=1'>[|<]</a> " & _
" <a class=menu href='"& pageurl &"page="& (pn-2)*pp+1 &"'>[<]</a> ")
end if
for pi=1+(pn-1)*pp to pn*pp
if cint(pi)>cint(thepages) then exit for
if cint(viewpage)=cint(pi) then
response.write(" <font color=#990000>[" & pi & "]</font> ")
else
response.write(" <a href='"& pageurl &"page="& pi &"'>[" & pi & "]</a> ")
end if
next
if cint(page_num)>1 and cint(pn)<>cint(page_num) then
response.write(" <a class=menu href='"& pageurl &"page="& pn*pp+1 &"'>[>]</a> " & _
" <a class=menu href='"& pageurl &"page="& thepages &"'>[>|]</a> ")
end if
end function
%>
[/code] |
以上分页速度都不行的
现在最好的好像只有叶子和nb]才子的分页.有兴趣的去查查
|
谢谢啦,我找到两个回去试试哦,主要是我是新手,又非专业,呵呵。只知道用些简单的东西。 |
|