asp记录集分页显示
DimoConn,oRs,sSqlSetoConn=Server.CreateObject("ADODB.Connection")OnErrorResumeNext'Ac...
Dim oConn, oRs, sSql
Set oConn = Server.CreateObject("ADODB.Connection")
On Error Resume Next
' Access数据库
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb")
Set oRs = Server.CreateObject( "ADODB.Recordset" )
sSql = "SELECT * FROM NewsData ORDER BY D_ID DESC"
oRs.Open sSql, oConn, 1, 1
要求对内容
<li>
<%If oRs("D_Picture") <> "" Then%>
<img width=20 height=10 border=1 src="<%=oRs("D_Picture")%>">
<%End If%>
<a href="show1.asp?id=<%=oRs("d_id")%>"><%=outHTML(oRs("d_title"))%></a>
分页显示.....如图... 展开
Set oConn = Server.CreateObject("ADODB.Connection")
On Error Resume Next
' Access数据库
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb")
Set oRs = Server.CreateObject( "ADODB.Recordset" )
sSql = "SELECT * FROM NewsData ORDER BY D_ID DESC"
oRs.Open sSql, oConn, 1, 1
要求对内容
<li>
<%If oRs("D_Picture") <> "" Then%>
<img width=20 height=10 border=1 src="<%=oRs("D_Picture")%>">
<%End If%>
<a href="show1.asp?id=<%=oRs("d_id")%>"><%=outHTML(oRs("d_title"))%></a>
分页显示.....如图... 展开
1个回答
展开全部
<!--#include file = "NewsSystem/st.asp"-->
<%
dim pre,last,page,intpage,i
Set oRs = Server.CreateObject( "ADODB.Recordset" )
sSql = "SELECT * FROM NewsData ORDER BY D_ID DESC"
oRs.PageSize = 30 '这里设定每页显示的记录数
oRs.CursorLocation = 3
oRs.Open sSql,oConn,0,2,1 '这里执行你查询SQL并获得结果记录集
pre = true
last = true
page = trim(Request.QueryString("page"))
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= oRs.PageCount then
intpage = oRs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not oRs.eof then
oRs.AbsolutePage = intpage
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style>
</head>
<body>
<%
for i=1 to oRs.PageSize
if oRs.EOF or oRs.BOF then exit for
%>
<li>
<%If oRs("D_Picture") <> "" Then%>
<img width=20 height=10 border=1 src="<%=oRs("D_Picture")%>">
<%End If%>
<a href="show1.asp?id=<%=oRs("d_id")%>"><%=outHTML(oRs("d_title"))%></a>
[<a href="modify.asp?id=<%=oRs("d_id")%>">修改</a>]
[<a href="delete.asp?id=<%=oRs("d_id")%>">删除</a>]
<%
oRs.movenext
next
%>
<%
if oRs.recordcount<1 then
Response.Write "现在数据库中还没有新闻!"
End if
%>
<table width="500" border="1" cellpadding="0" cellspacing="0" borderColorLight="#CCCCCC" borderColorDark="#FFFFFF" style="margin-top:5px;">
<tr bgcolor="#DFDFDF">
<td align="center" height="30">
<%if oRs.pagecount > 0 then%> 共<%=oRs.recordcount%>条记录 每<%=oRs.PageSize%>个/页 当前页: <%=intpage%>/<%=oRs.PageCount%> <%else%> 当前页: 0/0 <%end if%>
<a href="2.asp?page=1">首页</a> |
<%if pre then%>
<a href="2.asp?page=<%=intpage -1%>"> 上一页</a> | <%end if%>
<%if last then%>
<a href="2.asp?page=<%=intpage +1%>"> 下一页</a> | <%end if%>
<a href="2.asp?page=<%=oRs.PageCount%>">尾页</a> | 转到第
<select name="sel_page" onChange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to oRs.PageCount
if i = intpage then%>
<option value="2.asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="2.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select> 页 </font>
</td>
</tr>
</table>
</body>
</html>
<%
ors.Close()
Set ors= Nothing
%>
<%
dim pre,last,page,intpage,i
Set oRs = Server.CreateObject( "ADODB.Recordset" )
sSql = "SELECT * FROM NewsData ORDER BY D_ID DESC"
oRs.PageSize = 30 '这里设定每页显示的记录数
oRs.CursorLocation = 3
oRs.Open sSql,oConn,0,2,1 '这里执行你查询SQL并获得结果记录集
pre = true
last = true
page = trim(Request.QueryString("page"))
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= oRs.PageCount then
intpage = oRs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not oRs.eof then
oRs.AbsolutePage = intpage
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style>
</head>
<body>
<%
for i=1 to oRs.PageSize
if oRs.EOF or oRs.BOF then exit for
%>
<li>
<%If oRs("D_Picture") <> "" Then%>
<img width=20 height=10 border=1 src="<%=oRs("D_Picture")%>">
<%End If%>
<a href="show1.asp?id=<%=oRs("d_id")%>"><%=outHTML(oRs("d_title"))%></a>
[<a href="modify.asp?id=<%=oRs("d_id")%>">修改</a>]
[<a href="delete.asp?id=<%=oRs("d_id")%>">删除</a>]
<%
oRs.movenext
next
%>
<%
if oRs.recordcount<1 then
Response.Write "现在数据库中还没有新闻!"
End if
%>
<table width="500" border="1" cellpadding="0" cellspacing="0" borderColorLight="#CCCCCC" borderColorDark="#FFFFFF" style="margin-top:5px;">
<tr bgcolor="#DFDFDF">
<td align="center" height="30">
<%if oRs.pagecount > 0 then%> 共<%=oRs.recordcount%>条记录 每<%=oRs.PageSize%>个/页 当前页: <%=intpage%>/<%=oRs.PageCount%> <%else%> 当前页: 0/0 <%end if%>
<a href="2.asp?page=1">首页</a> |
<%if pre then%>
<a href="2.asp?page=<%=intpage -1%>"> 上一页</a> | <%end if%>
<%if last then%>
<a href="2.asp?page=<%=intpage +1%>"> 下一页</a> | <%end if%>
<a href="2.asp?page=<%=oRs.PageCount%>">尾页</a> | 转到第
<select name="sel_page" onChange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to oRs.PageCount
if i = intpage then%>
<option value="2.asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="2.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select> 页 </font>
</td>
</tr>
</table>
</body>
</html>
<%
ors.Close()
Set ors= Nothing
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询