将asp记录集分页

<divid="main_right"><h1><%=name%></h1><ul><%dimcolor,bold,rmp,picsetrs=server.createo... <div id="main_right">
<h1><%=name%></h1>

<ul>
<%
dim color,bold,rmp,pic
set rs = server.createobject("adodb.recordset")
sql = "select top 6 * from CMS_Article where CMS_Sort="&showid&" order by CMS_Date desc"
rs.open sql,conn,1,1
do while not rs.eof
title = rs("CMS_Title")
if len(title) > 20 then
title = left(title,20)
title = title & "..."
end if

color = rs("CMS_Color")

if rs("CMS_Bold") = 1 then
bold = " bold"
else
bold = ""
end if

if rs("CMS_Rmp") = 1 then
rmp = "<span style='color:blue'>[推荐]</span>"
else
rmp = ""
end if

if rs("CMS_Pic") = 1 then
pic = "<img src='images/pic.gif' alt='图片' />"
else
pic = ""
end if

%>
<li><em>[<%=FormatDateTime(rs("CMS_Date"),2)%>]</em><%=rmp%><img src="images/wenzhang.gif" width="15" height="15" /><%=pic%> <a href="detail.asp?ShowId=<%=rs("CMS_ID")%>" title="<%=title%>"><span class="<%=color%> <%=bold%>"><%=title%></span></a></li>
<%
rs.movenext
loop
%>
</ul>

</div>
将上面的记录集写成分页形式,谢谢啦
展开
 我来答
百度网友2fa8b9d
2010-08-09 · TA获得超过810个赞
知道小有建树答主
回答量:559
采纳率:0%
帮助的人:652万
展开全部
我在你代码基础上改的,你拷到你页试就可以测试了
<%

'PID 页面中的其它传参连接
'page 要显示的页码
'Vcount 总记录数
'Pnum 每页记录数
'className 超连接样式
public function ThePage(Pid,page,Vcount,Pnum,className)
dim show
page = int(page)
Pcount = abs(int(-abs(Vcount/Pnum)))
if page = "" or page <= 0 then page = 1
if page>Pcount then page=Pcount
StartPageNum=1
do while StartPageNum+10<=page
StartPageNum=StartPageNum+10
Loop
EndPageNum=StartPageNum+9

If EndPageNum>Pcount then EndPageNum=Pcount
show = show&"<tr><td colspan='10' bgcolor='' align='right' style='padding-right:25px;padding-top:5px;' class='"&className&"'>"
show = show&"共<b>"&Pcount&"</b>页 共有<b>"&Vcount&"</b>记录 第<b>"&page&"</b>页 跳到第 [ "
if StartPageNum>1 then
show = show&"<a class='"&className&"' href='?"&Pid&"page="&StartPageNum-1&"' title='前十页'><font face='webdings'>7</font></a>"
end if
For go=StartPageNum to EndPageNum

if go<>page then
show = show&"<a class='"&className&"' href='?"&Pid&"page="&go&"'>"&go&"</a>"
else
show = show&"<b>"&go&"</b>"
end if
show = show&" "
Next

if EndPageNum<Pcount then
show = show&"<a class='"&className&"' href='?"&Pid&"page="&EndPageNum+1&"' title='下十页'><font face='webdings'>8</font></a>"
end if
show = show& "] 页"

if page<>1 then
show = show&"<a class='"&className&"' href='?"&Pid&"page=1'> 首页</a> <a class='"&className&"' href='?"&Pid&"page="&page-1&"'>上一页</a>"
end if

if Pcount-page <> 0 then
show = show& "<a class='"&className&"' href='?"&Pid&"page="&page+1&"'> 下一页</a> <a class='"&className&"' href='?"&Pid&"page="&Pcount&"'>尾页</a>"
end if
show=show&"</tr></td>"
ThePage = show
end function
%>

<div id="main_right">
<h1><%=name%></h1>

<ul>

<%
set rs = server.createobject("adodb.recordset")
sql = "select * from CMS_Article where CMS_Sort="&showid&" order by CMS_Date desc"

'分页参数设置
page = request.querystring("page")
if page = "" then page = 1
page = int(page)
Pnum = 6
className = "lwf"
PID = ""
'以下不变
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1

Vcount = RS.recordcount
if RS.recordcount <> 0 then
RS.absoluteposition=RS.absoluteposition+((abs(page)-1)*Pnum)
end if

'********************************
i = 1
while not RS.eof and i<=Pnum

title = rs("CMS_Title")
if len(title) > 20 then
title = left(title,20)
title = title & "..."
end if

color = rs("CMS_Color")

if rs("CMS_Bold") = 1 then
bold = " bold"
else
bold = ""
end if

if rs("CMS_Rmp") = 1 then
rmp = "<span style='color:blue'>[推荐]</span>"
else
rmp = ""
end if

if rs("CMS_Pic") = 1 then
pic = "<img src='images/pic.gif' alt='图片' />"
else
pic = ""
end if
%>

<li><em>[<%=FormatDateTime(rs("CMS_Date"),2)%>]</em><%=rmp%><img src="images/wenzhang.gif" width="15" height="15" /><%=pic%> <a href="detail.asp?ShowId=<%=rs("CMS_ID")%>" title="<%=title%>"><span class="<%=color%> <%=bold%>"><%=title%></span></a></li>
<%
rs.movenext
i = i + 1
wend
rs.close
set rs = nothing
%>

</ul>

</div>
<%=ThePage(Pid,page,Vcount,Pnum,className)%>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式