ASP 数字分页效果代码,asp数字分页代码
ASP 数字分页效果代码,asp数字分页代码
最近网站改版正好发现原来的分页不带数字的,只有首页 上页 下页 末页 然后是select的跳转,都是以前比较流行的,而现在比较流行的是数字分页在中间,正好研究并分享下,需要的朋友可以参考下效果:
国外的核心代码:
<%
'digg style pagination script in asp.. written by Moazam... http://www.moazam.com/2007/03/30/asp-digg-style-pagination-script/
function getPaginationString(page, totalitems, limit, adjacents, targetpage)
'defaults
if not isnumeric(adjacents) then adjacents = 1 end if
if not isnumeric(limit) then limit = 15 end if
if not isnumeric(page) then page = 1 end if
if targetpage = "" then targetpage = "/" end if
margin = ""
padding=""
'other vars
prev = page - 1 'previous page is page - 1
nextPage = page + 1 'nextPage page is page + 1
lastpage = Ceil(totalitems , limit) 'lastpage is = total items / items per page, rounded up.
lpm1 = lastpage - 1 'last page minus 1
' Now we apply our rules and draw the pagination object.
' We're actually saving the code to a variable in case we want to draw it more than once.
pagination = ""
if lastpage > 1 then
pagination = pagination & "<div class=""pagination"""
if margin <> "" OR padding <> "" then
pagination = pagination & " style="""
if margin <> "" then
pagination = pagination & "margin: margin"
end if
if padding <> "" then
pagination = pagination & "padding: padding"
end if
pagination = pagination & """"
end if
pagination = pagination & ">"
'previous button
if page > 1 then
pagination = pagination & "<a href="""&targetpage&"&page="&prev&""">Prev</a>"
else
pagination = pagination & "<span class=""disabled"">Prev</span>"
end if
'pages
if lastpage < 7 + (adjacents * 2) then 'not enough pages to bother breaking it up
for counter = 1 to lastpage
if counter = page then
pagination = pagination & "<span class=""current"">"&counter&"</span>"
else
pagination = pagination & "<a href="""&targetpage&""&"&page="&counter&""">"&counter&"</a>"
end if
next
elseif lastpage >= 7 + (adjacents * 2) then 'enough pages to hide some
'close to beginning only hide later pages
if page < 1 + (adjacents * 3) then
for counter = 1 to (4 + (adjacents * 2))-1
if counter = page then
pagination = pagination & "<span class=""current"">"&counter&"</span>"
else
pagination = pagination & "<a href="""&targetpage&"&page="&counter&""">"&counter&"</a>"
end if
next
pagination = pagination & "..."
pagination = pagination & "<a href="""&targetpage&""&"&page="&lpm1&""">"&lpm1&"</a>"
pagination = pagination & "<a href="""&targetpage&""&"&page="&lastpage&""">"&lastpage&"</a>"
'in middle hide some front and some back
elseif lastpage - (adjacents * 2) > page AND page > (adjacents * 2) then
pagination = pagination & "<a href="""&targetpage&"&page=1"">1</a>"
pagination = pagination & "<a href="""&targetpage&"&page=2"">2</a>"
pagination = pagination & "..."
for counter = (page - adjacents) to (page + adjacents)
if counter = page then
pagination = pagination & "<span class=""current"">"&counter&"</span>"
else
pagination = pagination & "<a href="""&targetpage&"&page="&counter&""">"&counter&"</a>"
end if
next
pagination = pagination & "..."
pagination = pagination & "<a href="""&targetpage&"&page="&lpm1&""">"&lpm1&"</a>"
pagination = pagination & "<a href="""&targetpage&"page="&lastpage&""">"&lastpage&"</a>"
'close to end only hide early pages
else
pagination = pagination & "<a href="""&targetpage&"&page=1"">1</a>"
pagination = pagination & "<a href="""&targetpage&"&page=2"">2</a>"
pagination = pagination & "..."
for counter = (lastpage - (1 + (adjacents * 3))) To lastpage
if counter = page then
pagination = pagination & "<span class=""current"">"&counter&"</span>"
else
pagination = pagination & "<a href="""&targetpage&"&page="&counter&""">"&counter&"</a>"
end if
next
end if
end if
'nextPage button
if page < counter - 1 then
pagination = pagination & "<a href="""&targetpage&"&page="&nextPage&""">Next</a>"
else
pagination = pagination & "<span class=""disabled"">Next</span>"
end if
pagination = pagination & "</div>" & vbnewline
end if
getPaginationString = pagination
end function
function Ceil( dividend, divider)
if (dividend mod divider) = 0 Then
Ceil = dividend / divider
ELSE
Ceil = Int(dividend / divider) + 1
End if
End function
'test script code
page = 1
if request("page") <> "" then
page=cint(request("page"))
end if
ps = getPaginationString(page, 1500, 15, 2, "pagination.asp?foo=bar")
Response.Write("<br /><br /><br /><br /><br /><br /><br /><br />"&ps)
%>
完整打包代码:pagination(jb51.net).rar
看了有些头晕,还是看点简单的吧,asp与php思想差不多啊,参考了dedecms的修改方法
效果图:
核心代码:
ps=cint(pageno)-2
if ps<1 then
ps=1
end if
pe=clng(pageno)+5
if pe>mpage then pe=mpage
for i=ps to pe
if i=pageno then
lb=lb&"<strong>"&i&"</strong>"
else
lb=lb&"<a href=""/list/list_"&theid&"_"&i&".htm"">"&i&"</a>"
end if
next
完整代码:
pageno=cint(currentPage)
if cint(pageno)>1 then
lb=lb&"<a href=/list/list_"&theid&"_1.htm title=""首页"">首页</a>"
else
lb=lb&"<a href='#'>首页</a>"
end if
if cint(pageno)>1 and cint(pageno) then
lb=lb&"<a href=/list/list_"&theid&"_"&pageno-1&".htm title=""上页"">上页</a>"
else
lb=lb&"<a href='#'>上页</a>"
end if
ps=cint(pageno)-2
if ps<1 then
ps=1
end if
pe=clng(pageno)+5
if pe>mpage then pe=mpage
for i=ps to pe
if i=pageno then
lb=lb&"<strong>"&i&"</strong>"
else
lb=lb&"<a href=""/list/list_"&theid&"_"&i&".htm"">"&i&"</a>"
end if
next
if cint(pageno)<mpage and mpage>1 then
lb=lb&"<a href=/list/list_"&theid&"_"&pageno+1&".htm title=""下页"">下页</a>"
else
lb=lb&"<a href='#'>下页</a>"
end if
if cint(pageno)< mpage then
lb=lb&"<a href=/list/list_"&theid&"_"&mpage&".htm title=""末页"">末页</a>"
end if
ASP分页祥解
关于ASP分页的问题,对于初学者是一个比较重要的问题,也是各个网站运用最为广泛的技术,下面我就把我总结的一点小经验介绍给大家(写的不好,请大家指点)
1.原理:ASP分页其实是将数据库中的记录分割成若干段“分屏显示”
,为什么叫“分屏显示”显示,因为其实显示的原始页面只有1页,通过控制数据库显示,来刷新页面的显示内容(可能一些朋友会误会为动态产生若干页面来显示,呵呵,我刚刚学的时候也是这样以为的)
2.用到的几个函数
rs.pagesize--->定义一页显示记录的条数
rs.recordcount--->统计记录总数
rs.pagecount---->统计总页数
这几个函数相信大家都很快就明白意识了,不过还有一个函数它的用法可能理解起来难一点
rs.absolutepage--->将数据库指针移动到当前页要显示的数据记录的第一条记录,比如有20条记录的一个数据库,我们分为10条记录显示一页,当你的页面为2时,通过使用rs.absolutepage将指针移动到第11条记录处,依次类推....
3.大家明白原理后我们开始来看一段分页的程序,其中的一些文件我就不一一详细讲解了,不明白的朋友可以先看
--------------------------------------------------
<!--#include file=conn1.asp-->
<%
dim m,n
set rs=server.CreateObject("adodb.recordset")
sqlstr="select * from message order by time desc"
rs.open sqlstr,conn,3,3
rs.pagesize=10 '定义一页显示的记录数目
tatalrecord=rs.recordcount '获取记录总数目
tatalpages=rs.pagecount '获取分页的数目
rs.movefirst
----------------------------
nowpage=request("page") '用request获取当前页数,注意page是自己定义的变量并非函数
--------------------------
if nowpage&"x"="x" then '处理页码为空时的情况
nowpage=1
else
nowpage=cint(nowpage) '将页码转换成数字型
end if
--------------------------------
rs.absolutepage=nowpage '将指针移动到当前显示页的第一条记录
-------------------------------
%>
---------------------------------------------
<%
n=1
while not rs.eof and n<=rs.pagesize
response.Write(rs("user") & "<br>")
response.Write(rs("tt") & "<br>")
n=......余下全文>>
ASP分页是比较常见的功能,尤其是“首页 上一页 [1][2][3][4][5][6][7][8][9][10] 下一页 尾页”这种效果的数字分页,下边是实现代码供大家参考:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<!--#include file="conn.asp"-->
<% if trim(request("keywords"))="" then response.write("非法参数!") else%>
<% if trim(request("keywords"))<>"" then %>
<%
Function ReqStr(keywords)
keywords=request(keywords)
keywords=replace(keywords,"'","")
keywords=replace(keywords," ","")
keywords=replace(keywords,"and","")
keywords=replace(keywords,"or","")
keywords=replace(keywords," ","")
keywords=replace(keywords,"select","")
keywords=replace(keywords,"update","")
keywords=replace(keywords,"delete","")
keywords=keywords
End Function
response.write"keywords"
%>
<%
'**************
'分页导航栏函数
'输出wzpage值
'**************
Function pagination(pagecount)
Dim wzpage,wzpagecount,pagenum,boardid
boardid = Request.QueryString("board_id")
If boardid = 0 Then boardid = 1
If Len(Request.QueryString("p......余下全文>>
评论关闭