您的位置:首页 > 编程语言 > ASP

asp如何对access数据库的数据进行分页

2013-04-12 15:17 169 查看
<%
Mytype = request("newstype")
'response.write Mytype

exec = "select * from newscenter where newstype='" & Mytype & "'order by newstime desc"
'response.write exec
set rs = server.createobject("adodb.recordset")
rs.open exec,conn,1,1
infonum = rs.RecordCount

pageSize = 10
rs.PageSize = pageSize
pagecount = rs.PageCount
page = int(request.QueryString("page"))
'response.write pagecount
'response.write page
if page <= 0 then page = 1
if page > pagecount then page = pagecount
if request.QueryString("page") = "" then page = 1
'response.write page
'response.end
rs.AbsolutePage = page
count = 1
%>


<%
for i=1 to pageSize
if not rs.eof and count <= rs.PageSize then
%>
<tr>
<%=rs("newstitle")%>
<%=FormatDateTime(Rs("newstime"),vbShortDate)%>
</tr>
<%
count = count + 1
rs.movenext
end if
next
rs.close
set rs = nothing
%>


分页文章内容

<%if pagecount = 1 then%>
<< 起始页
< 上一页
> 下一页
>> 最终页

<%end if%>
<%if pagecount > 1 and page = 1  then%>
<< 起始页
< 上一页
<a href="news_list.asp?newstype=<%=Mytype%>&page=<%=page+1%>">> 下一页</a>
<a href="news_list.asp?newstype=<%=Mytype%>&page=<%=pagecount%>">>> 最终页</a>

<%end if%>
<%if pagecount > 1 and page>1 and page < pagecount then%>
<a href="news_list.asp?newstype=<%=Mytype%>&page=1"><< 起始页</a>
<a href="news_list.asp?newstype=<%=Mytype%>&page=<%=page-1%>">< 上一页</a>
<a href="news_list.asp?newstype=<%=Mytype%>&page=<%=page+1%>">> 下一页</a>
<a href="news_list.asp?newstype=<%=Mytype%>&page=<%=pagecount%>">>> 最终页</a>
<%end if%>
<%if pagecount > 1 and page = pagecount then%>
<a href="news_list.asp?newstype=<%=Mytype%>&page=1" target="_self"><< 起始页</a>
<a href="news_list.asp?newstype=<%=Mytype%>&page=<%=page-1%>">< 上一页</a>
> 下一页
>> 最终页

<%end if%>


显示上下页
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ASP