求源码!给分……

WzSzm 2004-08-11 08:41:35
我用ASP连Access数据库,我想在列表页里显示页数。
即像Google里的一样:1 2 3 下一页
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
aiguo25 2004-08-11
  • 打赏
  • 举报
回复
其实,就是主要的几个参数
rs.pagesize ‘定义每页显示记录的条数
rs.pagecount ’记录一共可以显示的页数
rs.absolutepage '你要显示的当前是第?页,用一个参数就可以传递过来
gu1dai 2004-08-11
  • 打赏
  • 举报
回复
太复杂了
dsclub 2004-08-11
  • 打赏
  • 举报
回复
在网上自己搜索ASP分页代码,会有好多的!何必在此提问
xiaoxingchi 2004-08-11
  • 打赏
  • 举报
回复
<!-- 一段经典的分页程序 -->

<SCRIPT type="text/javascript" language="javascript">
//点击[第一页]时响应
function PageFirst()
{
document.MyForm.CurrentPage.selectedIndex=0;
document.MyForm.CurrentPage.onchange();
}
//点击[上一页]时响应
function PagePrior()
{
document.MyForm.CurrentPage.selectedIndex--;
document.MyForm.CurrentPage.onchange();
}
//点击[下一页]时响应
function PageNext()
{
document.MyForm.CurrentPage.selectedIndex++;
document.MyForm.CurrentPage.onchange();
}
//点击[最后一页]时响应
function PageLast()
{
document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1;
document.MyForm.CurrentPage.onchange();
}
//选择"第?页"时响应
function PageCurrent()
{
document.MyForm.action='Pages.asp?Page='+(document.MyForm.CurrentPage.selectedIndex+1);
document.MyForm.submit();
}
</SCRIPT>


<%
'-------------------------------------------------------
'数据库结构说明:
'数据库类型: Access
'数据库文名: database.mdb
'表 名: book
'字 段:id 为自动编号
'其它字段可以任意创建...
'-------------------------------------------------------
'连接Access数据库
Set conn = Server.CreateObject("Adodb.Connection")
Set rs = Server.CreateObject("Adodb.Recordset")
cnpath = "Data Source = "& Server.MapPath("da.mdb")
conn.open "provider = microsoft.jet.oledb.4.0;" & cnpath

'设置每页显示10条记录数
rs.PageSize = 10

'执行SQL语句查询
SQLcmd = "Select * From bbs1 Order By announceid Desc"
rs.Open SQLcmd,conn,1,1

IF rs.Eof THEN
Response.Write("<Font size=2>数数据中没记录!</Font>")
ELSE

'指定当前页码
IF Request("CurrentPage") = "" THEN
rs.AbsolutePage=1
ELSE
rs.AbsolutePage=Clng(Request("CurrentPage"))
END IF

'创建表单MyForm方法为Get
Response.Write("<Form method=Get name=MyForm>")
IF rs.PageCount = 1 THEN
Response.Write("[第一页] [上一页] [下一页] [最后一页]")
ELSE
IF rs.AbsolutePage = 1 THEN
Response.Write(" [第一页] [上一页]")
Response.Write(" <A href=javascript:PageNext()>[下一页]</A>")
Response.Write(" <A href=javascript:PageLast()>[最后一页]</A>")
ELSE
IF rs.AbsolutePage = rs.PageCount THEN
Response.Write(" <A href=javascript:PageFirst()>[第一页]</A>")
Response.Write(" <A href=javascript:PagePrior()>[上一页]</A>")
Response.Write(" [下一页] [最后一页]")
ELSE
Response.Write(" <A href=javascript:PageFirst()>[第一页]</A>")
Response.Write(" <A href=javascript:PagePrior()>[上一页]</A>")
Response.Write(" <A href=javascript:PageNext()>[下一页]</A>")
Response.Write(" <A href=javascript:PageLast()>[最后一页]</A>")
END IF
END IF
END IF

'创建下拉列表
Response.Write(" 第<SELECT name=CurrentPage onchange=PageCurrent()>")
FOR i=1 TO rs.PageCount
IF rs.AbsolutePage = i THEN
Response.Write("<option selected>"&i&"</option>") '当前页码
ELSE
Response.Write("<option>"&i&"</option>")
END IF
NEXT
Response.Write("</SELECT>页 共"&rs.PageCount&"页 共"&rs.RecordCount&"条记录")
Response.Write("</FORM>")
END IF
%>
aspgreener 2004-08-11
  • 打赏
  • 举报
回复
下面是其中的一段,自己研究一下啊!
<%set rs=server.CreateObject("adodb.recordset")
sql="select * from reply_art where artid="&artid
rs.open sql,conn,1,1
dim newsperpage
newsperpage=5
if not rs.eof then
rs.movefirst
rs.pagesize=newsperpage
if trim(request("page"))<>"" then
currentpage=clng(request("page"))
if currentpage>rs.pagecount then
currentpage=rs.pagecount
end if
else
currentpage=1
end if
totalnews=rs.recordcount
if currentpage<>1 then
if (currentpage-1)*newsperpage<totalnews then
rs.move(currentpage-1)*newsperpage
dim bookmark
bookmark=rs.bookmark
end if
end if
if (totalnews mod newsperpage)=0 then
totalpages=totalnews\newsperpage
else
totalpages=totalnews\newsperpage+1
end if
i=0
author=rs("author")
content=rs("reply")
replytime=rs("posttime")
replyid=rs("replyid")
repid=rs("pid")
%>
<%do while not rs.eof and i<newsperpage
author=rs("author")
content=rs("reply")
replytime=rs("posttime")
replyid=rs("replyid")
repid=rs("pid")
j=(currentpage-1)*newsperpage+i+1
%>
<tr >
<td width="156" rowspan="2" valign="top"<%if j mod 2<>0 then response.write "class=td11" else response.write "class=td" end if%> >
  <%call level(repid)%> </td>
<td width="624" height="22" <%if j mod 2<>0 then response.write "class=td13" else response.write "class=td3" end if%>>    <a href="addfriends.asp?action=addf&fid=<%=repid%>"><img src="IMAGES/friend.gif" alt="将此人加为好友" width="48" height="18" border="0" align="absmiddle"></a> <a href="ownpage.asp?pid=<%=repid%>" target="_blank"><img src="IMAGES/profile.gif" width="45" height="18" border="0" align="absmiddle"> </a><a href="../mail/sendmsg.asp?touser=<%=author%>&pid=<%=repid%>"><img src="IMAGES/message.gif" alt="给此人发消息" width="60" height="18" border="0" align="absmiddle"></a> <a href="search.asp"><img src="IMAGES/find.gif" alt="我要搜索" width="45" height="18" border="0" align="absmiddle"></a>                  第<font color="#FF0000"><%=j%></font>楼</td>
</tr>
<tr >
<td width="624" height="150" valign="top" <%if j mod 2<>0 then response.write "class=td13" else response.write "class=td3" end if%>>
<%Response.Write HtmlSelfEnCode(content,image)%></td>
</tr>
<tr >
<td width="156" height="22" valign="middle" <%if j mod 2<>0 then response.write "class=td11" else response.write "class=td" end if%>><div align="center"><img src="IMAGES/ip.gif" width="13" height="15" border="0" align="absmiddle"> <%=replytime%></div></td>
<td width="624" valign="middle" <%if j mod 2<>0 then response.write "class=td13" else response.write "class=td3" end if%>>                                            <a href="edit.asp?replyid=<%=replyid%>&pid=<%=repid%>&action=reply&borderid=<%=borderid%>"><img src="IMAGES/edit.gif" width="47" height="18" border="0" align="absmiddle"></a> <a href="post.asp?artid=<%=artid%>&action=reply&borderid=<%=borderid%>"><img src="IMAGES/reply_a.gif" width="45" height="18" border="0" align="absmiddle"></a></td>
</tr>
<%
i=i+1
rs.movenext
loop
else
if rs.eof and rs.bof then
%>
<tr bgcolor="#FFFFFF">
<td height="22" colspan="3" align="center" class="chinese"><div align="center">当前没有回复!</div></td>
</tr>
<%end if
rs.Close
end if
%>
</table>
<table width="780" border="0" cellspacing="0" cellpadding="0" align="center" class="chinese">
<form name="form1" method="post" action="showart.asp">
<input type="hidden" name="artid" value="<%=artid%>">
<tr>
<td align="" bgcolor="#FFFFFF" style="border-bottom:1px solid #dedede; "> <font color="#666666">  共<%=totalnews%>条记录 <%=newsperpage%>/页 第<%=currentpage%>/<%=totalpages%>页</font>
</td><td align="right" bgcolor="#FFFFFF" style="border-bottom:1px solid #dedede; ">
分页:<%
if 1<currentpage then
if request("page")="" then
page=1
else
page=request("page")-1
%>
<a href="?page=<%=page%>&borderid=<%=request("borderid")%>" title="上一页"><font face=webdings color=#999999>9</font></a>

<%end if
end if
artid=request("artid")
i=1
showye=totalpages
if showye>10 then
showye=10
end if
for i=1 to showye
if i=currentpage then
%>
<%=i%>
<%else%>
<a href="?page=<%=i%>&artid=<%=artid%>"><%=i%></a>
<%end if
next
if totalpages>currentpage then
if request("page")="" then
page=1
else
page=request("page")+1
end if%>
<a href="?page=<%=page%>&artid=<%=artid%>" title="下一页"><font face=webdings color=#999999>:</font></a>
<%end if%>
     <input type="text" name="page" class="textarea" size="4">
<input type="submit" name="Submit" value="Go" class="button">  </td>
</tr>
</form>
</table>

28,390

社区成员

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

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