asp分页

hgc8888 2009-09-29 06:36:39
<!--#include file="Conn.asp"-->
<body>
<table border="0" align="left" cellpadding="0" cellspacing="0">
<%

URL= Request.ServerVariables("URL")
sql="select * from news order by N_id desc"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<tr><td colspan=9 height=40><center>暂无内容</center></td></tr>"
PageScript="ML"
else
'分页的实现
listnum=3
Rs.pagesize=listnum
pageMax=rs.pagecount
listCount=rs.recordcount

page=Request("page")
if (page-pageMax) > 0 then
page=pageMax
elseif page = "" or page < 1 then
page = 1
end if
rs.absolutepage=page
'编号的实现
j=listCount
j=j-(page-1)*listnum
i=0
nn=request("page")
if nn="" then
n=0
else
nn=nn-1
n=listnum*nn
end if

do while not rs.eof and i<listnum
n=n+1
%>
<tr>
<td>
<a href="#"><%=rs("N_title")%></a>
</td>
</tr>
<%
rs.movenext
i=i+1
j=j-1
loop
end if
rs.close
set rs=nothing
%>
<%filename=URL%>

<tr class="pages" valign="middle">
<td align=right id="bottomPage">共 <%=listCount%> 条  <%=listnum%> 条/页  共 <%=pageMax%> 页
<% if page>1 then %>
<a href=<%=filename%>>首页</a>
<a href=<%=filename%>?page=<%=page-1%>>上一页</a>
<%else%>
<a href=<%=filename%>>首页</a>

<%end if%>
<%
pageArea=(page\10)*10
for i=pageArea-5 to pageArea+10
if i>0 and i<=pageMax then
if i=cint(page) then
response.write("<strong><font class=bg>"&i&"</font></strong>")
else
response.write("<a href="&filename&"?page="&i&">"&i&"</a>")
end if
end if
next
%>
<% if pageMax-page <> 0 then %>
<a href=<%=filename%>?page=<%=page+1%>>下一页</a>
<a href=<%=filename%>?page=<%=pageMax%>>末页</a>
<%else%>

<a href=<%=filename%>?page=<%=pageMax%>>末页</a>
<%end if%>
<select name='sldd' style='width:45px; height:20px;' onchange='location.href=this.options[this.selectedIndex].value;'>
<%
pageArea=(page\10)*10
for i=pageArea-5 to pageArea+10
if i>0 and i<=pageMax then
if i=cint(page) then %>
<option value='' selected="selected"><%=i%>页</option>
<%else%>
<option value='<%=filename%>?page=<%=i%>'><%=i%>页</option>
<%end if
end if
next
%>
</select>
</td>
</tr>
</table>

--------------------------------------------
上面是人家的数字分页程序
我的连接参数id=request.QueryString("id")
怎么修改上面代码就可以实现分页效果
红色的代码是什么意思分析以下好吧
...全文
139 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
MR丶CHAN 2009-09-29
  • 打赏
  • 举报
回复
外面有了双引号,里面就用单引
hgc8888 2009-09-29
  • 打赏
  • 举报
回复
没有人能回答这个问题吗
我在<a href="&filename&"?page="&i&">里想加个id参数啊
因为不加它 下页传递的值就收不到了
一加就出现错误或分页数值变成了flase~~
都来想想办法啊
zhangjiewoshiwo 2009-09-29
  • 打赏
  • 举报
回复
汗。。。怎么分页都直接写在代码里的啊!这样访问的速度会有点慢!一般的都是用存储过程来写分页的。。。
街头小贩 2009-09-29
  • 打赏
  • 举报
回复
示例:
http://www.t6new.cn/trac/bookstack.asp
数字的css可以从示例网址上看到
街头小贩 2009-09-29
  • 打赏
  • 举报
回复
调用示例:

strSQL="SELECT b.ID, b.bookname,b.price,b.author,b.isbn,b.coverimgurl,f.title AS publisher,f.refurl AS url FROM bookstack b INNER JOIN favorite f ON b.publishid=f.ID ORDER BY b.builddate DESC"
set strRs=Server.CreateObject("ADODB.Recordset")
strRs.Open strSQL,conn,1,1

If NOT strRs.EOF then
'分页代码
Dim CurrentPage
Dim jumpPage:jumpPage="bookstack.asp"
If Not IsEmpty(Request.QueryString("page")) then
CurrentPage=CInt(Request.QueryString("page"))
Else
CurrentPage=1
End If

strRs.PageSize=5
If CurrentPage<1 then CurrentPage=1
If CurrentPage>strRs.PageCount then CurrentPage=strRs.PageCount
If Not strRs.EOF Then
strRs.AbsolutePage=CurrentPage
End If
Dim I:I=0
'分页代码
do while NOT strRs.EOF%>
<div class="bookitem"><div class="bookcover"><img src="../images/<%=strRs("coverimgurl")%>" border="0" class="coverimg" /></div><div class="bookinfo"><span><a href='../main/display.asp?model=bookstack&subject=<%=Server.URLEncode(strRs("bookname"))%>&tag=1' target='_blank'><%=strRs("bookname")%></a></span><dl><dt>By:</dt><dd><%=strRs("author")%></dd></dl><dl><dt>Publisher:</dt><dd><a href="<%=strRs("url")%>" target="_blank"><%=htmluncodexml(strRs("publisher"))%></a></dd></dl><dl><dt>ISBN-13:</dt><dd><%=strRs("isbn")%></dd></dl><dl><dt>Price:</dt><dd><%=strRs("price")%>¥</dd></dl></div></div>
<%
'分页代码
I=I+1
If I>=strRs.PageSize then Exit Do
'分页代码
strRs.MoveNext
Loop
Else
Response.Write "no resultset"
End If%>
</div>
<div id="pagepanel"><%call showpage(jumpPage,strRs.RecordCount,strRs.PageSize,CurrentPage,5,"current",true)%></div>
<%
strRs.Close
set strRs=Nothing
CloseDatabase
%>
街头小贩 2009-09-29
  • 打赏
  • 举报
回复
小可拙笔写的一个数字分页过程:

<%

'***********************************************
'函数名:PasteURL
'作 用:向地址中加入 ? 或 &
'参 数:strUrl ----网址
'返回值:加了 ? 或 & 的网址
'***********************************************
function PasteURL(strUrl)
if strUrl="" then
PasteURL=""
exit function
end if
'如果传入的URL末尾不是"?",有两种情况:
'1.无“?”,此时需加入一个“?”
'2. 有“?”再判断有无“&”
if InStr(strUrl,"?")<len(strUrl) then
if InStr(strUrl,"?")>1 then
if InStr(strUrl,"&")<len(strUrl) then
PasteURL=strUrl & "&"
else
PasteURL=strUrl
end if
else
PasteURL=strUrl & "?"
end if
else
PasteURL=strUrl
end if
end function

'***********************************************
'过程名:ShowPage
'作 用:显示“上一页 下一页”等信息
'参 数:sDesURL ----链接地址,可以是一个文件名,也可以是一个有一些参数所URL
' nTotalNumber ----总数量
' nMaxPerPage ----每页数量
' nCurrentPage ----当前页
' nBlock ----数字页码可示段的数量
' cPageStyle ----当前页码的CSS样式
' bSymbol ----是否显示标记位
'***********************************************
sub ShowPage(sDesURL, nTotalNumber, nMaxPerPage, nCurrentPage,nBlock,cPageStyle,bSymbol)
dim n, i,strTemp,strUrl,strStyle,poutStr
'计算页数
if nTotalNumber mod nMaxPerPage=0 then
n= nTotalNumber \ nMaxPerPage
else
n= nTotalNumber \ nMaxPerPage+1
end if
'判断nCurrentPage
if nCurrentPage < 1 then
nCurrentPage = 1
elseif nCurrentPage > n then
nCurrentPage = n
end if
strStyle=cPageStyle
If strStyle="" then strStyle="current"
'根据输入的sDesURL向它加入?或&
strUrl=PasteURL(sDesURL)
poutStr="<dl>"
if nCurrentPage<2 then
poutStr=poutStr&"<dt>INDEX</dt> <dt>PREV</dt>"
else
poutStr=poutStr& "<dt><a href='" & strUrl & "page=1'>INDEX</a></dt>"
poutStr=poutStr& "<dt><a href='" & strUrl & "page=" & (nCurrentPage-1) & "'>PREV</a></dt>"
end if
'mm页码标量
'limax数字页码的可示上限
'lilow数字页码的可示下限
'lisymbol上一个可示段的上限
'outStr数字页码的缓存字符串
Dim mm,limax,lilow,lisymbol,outStr

If n>1 then
outStr= "<dd><ul>"
'数字页码的可示上限
if nCurrentPage Mod nBlock >0 then
limax=((nCurrentPage \ nBlock) * nBlock) + nBlock
else
limax=(nCurrentPage \ nBlock) * nBlock
end if
'数字页码的可示下限
lilow=limax - nBlock+1
if limax>n then limax=n
'显示上一个标记位
if bSymbol then
if lilow mod nBlock>0 And lilow>1 then
lisymbol=lilow - 1 - nBlock
if lisymbol=0 then lisymbol=1
outStr=outStr& "<li><a href='" & strUrl & "page="&lisymbol&"'>"&lisymbol&"</a></li><li> ... </li>"
end if
end if
'打印数字页码
for mm=lilow to limax
outStr=outStr& "<li>"
if mm=nCurrentPage then
outStr=outStr& "<span class='"&strStyle&"'>"&mm&"</span>"
else
outStr=outStr& "<a href='" & strUrl & "page="&mm&"'>"&mm&"</a>"
end if
outStr=outStr& "</li>"
next
'显示最后一个标记位
if bSymbol then
if limax<n then
outStr=outStr& "<li> ... </li><li><a href='" & strUrl & "page="&n&"'>"&n&"</a></li>"
end if
end if
outStr=outStr& "</ul></dd>"
poutStr=poutStr&""&outStr
End If
if n-nCurrentPage<1 then
poutStr=poutStr& "<dt>NEXT</dt><dt>END</dt>"
else
poutStr=poutStr& "<dt><a href='" & strUrl & "page=" & (nCurrentPage+1) & "'>NEXT</a></dt>"
poutStr=poutStr& "<dt><a href='" & strUrl & "page=" & n & "'>END</a></dt>"
end if
poutStr=poutStr&"</dl><label>showing "&((nCurrentPage-1)*nMaxPerPage)+1&" - "
if nCurrentPage*nMaxPerPage> nTotalNumber then
poutStr=poutStr&""&nTotalNumber
else
poutStr=poutStr&""&nCurrentPage*nMaxPerPage
end if
poutStr=poutStr&" of "&nTotalNumber&"</label>"
Response.Write poutStr
end sub

hgc8888 2009-09-29
  • 打赏
  • 举报
回复
response.write("<a href="&filename&"?page="&i&">"&i&"</a>")
我想在这句代码中在加个参数 id~
可是符号把我弄混了~~
帮个忙~~~~
hookee 2009-09-29
  • 打赏
  • 举报
回复
URL= Request.ServerVariables("URL") 取本页的地址
rs.absolutepage=page ' 取记录集的第几页,上面的定义的page指定了页数
j=listCount ' j是记录的总数
j=j-(page-1)*listnum ' 记录数-页数X每页的记录数 得到当前页的记录开始时剩余的记录数
i=0
nn=request("page") ' 此处为何要取page? page之前已经得到了
if nn="" then
n=0 ' 第一页 n=0 编号从0开始(下面有n+1,n实际的开始值就是1)
else
nn=nn-1
n=listnum*nn '第nn页,n=每页记录X(页数-1) 就是当前页的记录开始的编号
end if

do while not rs.eof and i <listnum '显示一页listnum条记录,如果是最后一页,可能不到listnum条记录,则判断到 rs.eof结束循环
n=n+1 'n 是编号
rs.movenext
i=i+1 '计数用于判断i <listnum
j=j-1 '剩余的记录数-1
loop

<%filename=URL%> 分页每页的都是同一个程序,所以用此变量做转页的连接

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧