① asp如何分页
<%
dim rs,strsql
set rs=server.CreateObject("ADODB.recordset")
strsql="select * from users where level=0 order by id desc"
rs.open strsql,conn,1,1
IF Rs.Recordcount>0 Then
Rs.PageSize=20'每页最多显示多少条记录
Page=Clng(Request.QueryString("Page"))
IF Page>Rs.PageCount Then Page=Rs.PageCount
IF Page<1 Then Page=1
Rs.Absolutepage=Page
For i=1 To Rs.PageCount
%>
<tr><td>
<%=rs("name")%>
</td><td>
<%=rs("school")%>
</td><td>
<%=rs("tel")%>
</td></tr>
<%
rs.movenext
IF Rs.Eof Then Exit For
Next
%>
<tr><td colspan="3">当前页码<%=Page&"/"&Rs.PageCount%> <a href="?Page=1">首页</a> <a href="?Page=<%=Page-1%>">上一页</a> <a href="?Page=<%=Page+1%>">下一页</a> <a href="?Page=<%=Rs.PageCount%>">尾页</a></td></tr>
② ASP中记录集如何分页
虽然可以用记录集的 PageSize(每页记录数)、PageCount(总页数)和AbsolutePage(当前页码)三个属性来分页,但是不推荐这么做。
我通常是把所有ID抓下来进行手工分页,再根据需要读取当前页所有记录。
③ 一个关于ASP数据库分页的问题请教
是这样的,你的每页都循环写出20条记录
前两页都是正确的因为他们都满足够20条记录这个条件,所以指针不会跑出记录之外
而第三页不足20条,所以当它到第十六条记录时,就会跑出记录之外
而这时,当指针在记录之外,却要引用记录集某个字段时,就会出错
系统报错,就会出现什么eof,bof之类的
解决方法
在每次操作数据时都要加上一个验证语句,如我这样写
for i=1 to rs.reocrdcount
if not rs.bof and not rs.eof then
'读出数据
else
exit for
end if
next
明白我的意思了吗?
④ asp怎么分页显示啊
作为一个程序员详细代码你还是自己写吧,这里只给个思路:分页的原理就是每次点击下一页的时候url中传递一个页面的变量到ASP页面,这个ASP页面在哪用到这个变量呢?就是在SELECT语句中用到的,比如说你每次从数据库中取10条记录(相当于设置每页显示10条),那个变量就是取记录的起始位置,大体就是这样了,具体代码中你要先算出总共记录条数,你想每页显示多少条,从而再算出总共多少页
⑤ 如何实现ASP分页功能
我来试试看:
<!--#include file="conn.asp"-->
<%
set rsc=server.createobject("adodb.recordset")
sqlc="select * from news where class='"&rs("class")&"' order by id desc"
rsc.open sqlc,conn,1,1
Response.write "<center>"
rsc.PageSize = 10 'pagesize属性指定了每页要显示的记录条数
Page = CLng(Request("Page")) ’string型转化为long型
If Page < 1 Then Page = 1
If Page > rsc.PageCount Then Page = rsc.PageCount
If Page <> 1 Then
Response.Write "<A HREF=emp1.asp?Page=1>第一页</A>�"
Response.Write "<A HREF=emp1.asp?Page=" & (Page-1) & ">上一页</A>�"
End If
If Page <> rsc.PageCount Then
Response.Write "<A HREF=emp1.asp?Page=" & (Page+1) & ">下一页</A>�"
Response.Write "<A HREF=emp1.asp?Page="& rsc.PageCount & ">最后一页</A>�"
End If
Response.write "页码:" & Page & "/" & rsc.PageCount & "</center><table border=1>"
rsc.AbsolutePage = Page '把页码赋给absolutepage属性从而知当前页的首条记录号
For iPage = 1 To rsc.PageSize
%>
<tr>
<td width="574" bordercolor="#CCCCCC" class="classlist"><div align="left" class="classlist"><span class="classlist"><a href="news.asp?id=<%=rsc("id")%>"><%=rsc("title")%></a></span></div></td>
<td width="196" height="16" bordercolor="#CCCCCC" ><%=rsc("time")%></td>
<td width="112" height="16" bordercolor="#CCCCCC" ><%=rsc("by")%></td>
<%
rsc.MoveNext
If rsc.EOF Then Exit For
Next
%>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
<br />
<table width="100%" border="1" bordercolor="#FFFFFF">
<tr>
<td width="100%" bordercolor="#CCCCCC">
td>
</tr>
</table>
</div>
</body>
</html>
<%
rs.close
rsc.close
set rs=nothing
set rsc=nothing
conn.close
set conn=nothing
%>
⑥ asp中关于分页设置的问题(尤其是首页和最后一页)怎么在服务器行为中设置
完整分页代码:
<%
set rs=server.createobject("adodb.recordset")
sql="select * from [news] where cp_type='新闻中心' order by uptime desc"
rs.open sql,conn,1,1
if not rs.eof then
rs.pagesize=10 '定义一页显示的记录数目
tatalrecord=rs.recordcount '获取记录总数目
tatalpages=rs.pagecount '获取分页的数目
nowpage=request("page") '用request获取当前页数,注意page是自己定义的变量并非函数
if nowpage&"x"="x" then '处理页码为空时的情况
nowpage=1
else
nowpage=cint(nowpage) '将页码转换成数字型
end if
rs.absolutepage=nowpage '将指针移动到当前显示页的第一条记录'
n=0
%>
<div align="right">共:<%=tatalpages%>页 当前为:<%=nowpage%>页
<%if nowpage>1 then%>
<a href="?page=<%=nowpage-1%>" class="yangshi1">上一页</a>
<%else%>
上一页
<%end if%>
<%for k=1 to tatalpages%>
<%if k<>nowpage then %>
<a href="?page=<%=k%>" class="yangshi1"><%=k%></a>
<%else%>
<%=k%>
<%end if%>
<%next%>
<%if nowpage < tatalpages then%>
<a href="?page=<%=nowpage+1%>" class="yangshi1">下一页</a>
<%else%>
下一页
<%end if%>
<%if nowpage<>1 then%>
<a href="?page=<%=1%>" class="yangshi1">首页</a>
<%else%>
首页
<%end if%>
<%if nowpage<>tatalpages then %>
<a href="?page=<%=tatalpages%>" class="yangshi1">末页</a>
<%else%>
末页
<%end if%>
</div>
⑦ ASP中怎么分页显示数据库里的数据
Sub show()
logusername = replace(trim(request.Querystring("logusername")),"'","")
if logusername <> "" then
sql="select * from JB_log where username='"+ logusername +"' order by logid desc"
logpage = "&logusername="& logusername
logtext = "当前显示<font color=red>"& logusername &"</font>的操作日志 | <a href=""logs.asp"">显示全部</a>"
else
sql="select * from JB_log order by logid desc"
End if
set rs = server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
%>
<table height="29" border="0" align="center" cellpadding="0" cellspacing="0" class="table-noColor">
<form name="form2" method="Get" action="logs.asp"><tr>
<td>输入操作人:
<input name="logusername" type="text" id="logusername" size="16" maxlength="20">
<input type="submit" name="Submit3" value="搜索"><%=logtext%>
</td>
</tr></form>
</table>
<table border="0" align="center" cellpadding="3" cellspacing="1" class="table">
<form name="form4" method="post" action="logs.asp?action=del"><tr>
<td class="table-title">操作人</td>
<td class="table-title">操作时间</td>
<td class="table-title"> 操作内容/文章作者</td>
<td class="table-title">操作理由/扣分</td>
<td class="table-title" align="center">内容</td>
<td class="table-title">操作时IP</td>
<%
if userID=33 and usergroup=1 then
%>
<td width="15" class="table-title">
</td>
<%
end if
%>
</tr>
<%
if not(rs.Eof and rs.Bof) then
page = trim(request.form("page"))
if page = "" then page = trim(request.QueryString("page"))
if Not(IsNumeric(page)) or page = "0" then page = 1
rs.pageSize = 60
pageCount = rs.pageCount
if len(page) > 4 then page = pageCount
if Cint(page) > Cint(pageCount) then page = pageCount
rs.absolutepage = page
color2 = 0
for i = 1 to rs.pagesize
if rs.eof then exit for
if color2 mod 2 = 0 then
color1 = "Class=""table-dark"""
else
color1 = "Class=""table-light"""
end if
%>
<tr <%=color1%>>
<td><%="<a href=""user.asp?userid="&rtrim(rs("userid"))&""" target=""_blank"">"&rtrim(rs("username"))&"</a>"%></td>
<td><%=rtrim(rs("logtime"))%></td>
<td><%=rtrim(rs("logC"))%></td>
<td><%=rtrim(rs("reason"))%></td>
<td align="center"><a href="?action=showlog&logid=<%=rs("logid")%>">
<%if trim(rs("oldcontent")) <> "" then response.Write("查看") end if%>
</a></td>
<td><%=rtrim(rs("logIP"))%></td>
<%
if userID=33 and usergroup=1 then
%>
<td align="center">
<input name="logid" type="checkbox" id="logid" value="<%=trim(rs("logid"))%>">
</td>
<%
End if
%>
</tr>
<%
rs.MoveNext
color2=color2+1
Next'i
End if
if userID=33 and usergroup=1 then
%>
<tr align="right" <%=color1%>>
<script language="javascript">
function AllSet(theForm)
{
for(i=0;i<document.form4.length;i++)
if(document.form4.elements[i].type=="checkbox")
document.form4.elements[i].checked=1}
function Reverse()
{
for(i=0;i<document.form4.length;i++)
if(document.form4.elements[i].type=="checkbox")
if(document.form4.elements[i].checked==1)
document.form4.elements[i].checked=0
else
document.form4.elements[i].checked=1}
function ReSet()
{
for(i=0;i<document.form4.length;i++)
if(document.form4.elements[i].type=="checkbox")
if(document.form4.elements[i].checked==1)
document.form4.elements[i].checked=0}
</script>
<td colspan="7">
<input name="button" type=button onclick="AllSet()" value="全选">
<input name="button" type=button onclick="Reverse()" value="反选">
<input name="button" type=button onclick="ReSet()" value="不选">
<input name="Submit" type="submit" id="Submit" value="删除所选"></td>
</tr>
<%
End if
%>
</form>
</table>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="table-noColor">
<tr>
<td>
<%
if pagecount < 1 then pagecount = 1
response.Write "页次:"& PAGECOUNT &"/" & page &"页 每页"& rs.pageSize &" 记录"&rs.recordCount&" "
%>
</td>
<td height="30">分页:
<%
beginpage = 1
endpage = CInt(pagecount)
page = CInt(page)
if pagecount >= 9 then
if page >= 5 then
beginpage = page - 4
if page <= (pagecount - 4) then
endpage = page + 4
else
endpage = pagecount
beginpage = pagecount - 4
end if
else
beginpage = 1
endpage = 9
end if
end if
if beginpage>1 then response.write "<a title=""第一页"" href=""logs.asp?"& logpage &"""><font face=webdings>9</font></a>"
for j = beginpage to endpage
if j = page then
response.write"<b>[" & j & "]</b>"
else
response.write"<a href=""logs.asp?page=" & j & logpage &""">[" & j & "]</a>"
end if
next
if endpage < pagecount then response.write "<a title=""最末页"" href=""logs.asp?page="& pagecount & logpage &"""><font face=webdings>:</font></a>"
%>
</td>
<form name="form1" method="post" action="">
<td align="right">转到:第
<input name="page" type="text" size="3" maxlength="5">
<input type="submit" name="Submit2" value="页">
</td>
</form>
</tr>
</table>
<%
rs.close
set rs = nothing
End Sub
⑧ 如何用asp的数据集实现分页效果啊
ASP项目中的公共翻页模块
<%
'+++++++++++++++++++++++++++++++++++++
'◆模块名称: 公共翻页模块
'◆文 件 名: TurnPage.asp
'◆传入参数: Rs_tmp (记录集), PageSize (每页显示的记录条数)
'◆输 出: 记录集翻页显示功能
'+++++++++++++++++++++++++++++++++++++
'
Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 记录集 ; PageSize 每页显示的记录条数;
Dim TotalPage '总页数
Dim PageNo '当前显示的是第几页
Dim RecordCount '总记录条数
Rs_tmp.PageSize = PageSize
RecordCount = Rs_tmp.RecordCount
TotalPage = INT(RecordCount / PageSize * -1)*-1
PageNo = Request.QueryString ("PageNo")
'直接输入页数跳转;
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo")
'如果没有选择第几页,则默认显示第一页;
If PageNo = "" then PageNo = 1
If RecordCount <> 0 then
Rs_tmp.AbsolutePage = PageNo
End If
'获取当前文件名,使得每次翻页都在当前页面进行;
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
postion = InstrRev(fileName,"/")+1
'取得当前的文件名称,使翻页的链接指向当前文件;
fileName = Mid(fileName,postion)
%>
<table border=0 width='100%'>
<tr>
<td align=left> 总页数:<font color=#ff3333><%=TotalPage%></font>页
当前第<font color=#ff3333><%=PageNo%></font>页</td>
<td align="right">
<%If RecordCount = 0 or TotalPage = 1 Then
Response.Write "首页|前页|后页|末页"
Else%>
<a href="<%=fileName%>?PageNo=1">首页|</a>
<%If PageNo - 1 = 0 Then
Response.Write "前页|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前页|</a>
<%End If
If PageNo+1 > TotalPage Then
Response.Write "后页|"
Else%>
<a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后页|</a>
<%End If%>
<a href="<%=fileName%>?PageNo=<%=TotalPage%>">末页</a>
<%End If%></td>
<td width=95>转到第
<%If TotalPage = 1 Then%>
<input type=text name=PageNo size=3 readonly disabled style="background:#d3d3d3">
<%Else%>
<input type=text name=PageNo size=3 value="" title=请输入页号,然后回车>
<%End If%>页
</td>
</tr>
</table>
<%End Sub%>
当然,大家可以把翻页的链接做成图片按钮,这样的话也面就更加美观了。
调用方法:
1、在程序开始或要使用翻页的地方包含翻页模块文件;
2、定义变量:RowCount,每页显示的记录条数
3、调用翻页过程:Call TurnPage(记录集,RowCount)
4、在Do While 循环输出记录集的条件中加上" RowCount > 0 " 条件
5、在循环结束 "Loop前" 加上: RowCount = RowCount - 1
'-----------------------------------------------------
调用范例:
文件名:News.asp
<%
Dim Conn,Rs_News
Set Conn = server.CreateObject("ADODB.CONNECTION")
Conn.Open "cpm","cpm","cpm"
Dim Sql
Sql = "Select * from News"
Set Rs_News = Server.CreateObject("ADODB.RECORDSET")
Rs_News.Open Sql,Conn,1,3 '获取的记录集
'公共翻页模块开始%>
<!--#include file=../Public/TurnPage.asp-->
<%
Dim RowCount
RowCount = 10 '每页显示的记录条数
Call TurnPage(Rs_News,RowCount)
'公共翻页模块结束%>
<table width=100%>
<tr>
<td>新闻编号</td>
<td>新闻标题</td>
<td>发布日期</td>
<tr>
<%
If Not Rs_News.eof
Do while Not Rs_News.eof and RowCount>0
%>
<tr>
<td><%=Rs_News("ID")%></td>
<td><%=Rs_News("Name")%></td>
<td><%=Rs_News("Date")%></td>
<tr>
<%
RowCount = RowCount - 1
Rs_News.MoveNext
Loop
End If
%>
⑨ asp如何分页显示
<% Response.Buffer=False %>
<%
Dim connstr
set bb = server.CreateObject("ADODB.Connection")
bb.open"driver=driver do microsoft access (*.mdb);uid=;pwd=;dbq="&server.MapPath("mychanpin.mdb")
%>
<html>
<head>
<title>每日销售情况</title>
</head>
<body>
<% '=============分页定义开始,可放在数据库打开前或后
dim action
action=request.QueryString("action")
Const MaxPerPage=20 '定义每页显示记录数,可根据实际自定义
dim totalPut
dim CurrentPage
dim TotalPages
dim j
dim sql
if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end if '=============分页定义结束
%>
<%
set rs = server.CreateObject ("adodb.recordset")
sql="select * from changpin"
rs.open sql,bb,1,1
%>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">序号</div></td>
<td><div align="center">日期</div></td>
<td><div align="center">已售</div></td>
</tr>
<%
'=============分页类代码开始,需放在数据库数据表打开后
if err.number<>0 then
response.write "<p></p><p align='center'>数据库中暂时无数据!</p><p></p>"
end if
if rs.eof And rs.bof then
Response.Write "<p></p><p align='center'>对不起,没有符合条件记录!</p><p></p>"
else
totalPut=rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showContent
showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""
else
currentPage=1
showContent
showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&""
end if
end if
end if '=============分页类代码结束onmouseover="this.background=' /images/999999.jpg'" onmouseout="this.background=' /images/1w.jpg'"
%>
<% '=============循环体开始
sub showContent
dim i
i=0
i=1
do while not rs.eof
%>
<tr>
<td><div align="center"><%=rs("ID")%></div></td>
<td><div align="center"><%=rs("data")%></div></td>
<td><div align="center"><%=rs("yishou")%></div></td>
</tr>
<%
i=i+1
if i>=MaxPerPage then Exit Do
rs.movenext
loop
%>
</table>
<%'=============放置分页显示开始
rs.close '释放资源
set rs=nothing
End Sub '=============循环体结束
Function showpage(totalnumber,maxperpage,filename)
Dim n
If totalnumber Mod maxperpage=0 Then
n= totalnumber \ maxperpage
Else
n= totalnumber \ maxperpage+1
End If %>
<form method=Post action=<%=filename%>>
<p align="center" class="STYLE13">
<%If CurrentPage<2 Then %>
第一页 上一页
<% Else %>
<a href=<% = filename %>?cx=<% =s %>&page=1>第一页</a>
<a href=<% = filename %>?cx=<% =s %>&page=<% = CurrentPage-1 %>>上一页</a>
<% End If
If n-currentpage<1 Then %>
下一页 尾 页
<% Else %>
<a href=<% = filename %>?cx=<% =s %>&page=<% = (CurrentPage+1) %>>下一页</a>
<a href=<% = filename %>?cx=<% =s %>&page=<% = n %>>尾 页</a>
<% End If %>
页次:<b><font color=red>
<% = CurrentPage %>
</font></b>/<b><% = n %></b>页 <b><%=maxperpage%></b>个记录/页 共<b><%=totalnumber %></b>个记录
转到:<select name="cndok" class="STYLE15" onChange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to n
if i = CurrentPage then %>
<option value="<% = filename %>?cx=<% =s %>&page=<%=i%>" selected>第<%=i%>页</option>
<%else%>
<option value="<% = filename %>?cx=<% =s %>&page=<%=i%>">第<%=i%>页</option>
<%
end if
next
%>
</select></font>
</form></td>
</tr>
</table>
<% End Function '=============放置分页显示结束%>
</body>
</html>
⑩ 求asp大数据时的分页代码
<% sql = "select……………………省略了sql语句
Set rs=Server.Createobject("ADODB.RECORDSET")
rs.Open sql, conn, 1, 1
if not rs.eof then
pages = 30 ’定义每页显示的记录数
rs.pageSize = pages ’定义每页显示的记录数
allPages = rs.pageCount’计算一共能分多少页
page = Request.QueryString("page")’通过浏览器传递的页数
’if语句属于基本的排错处理
if isEmpty(page) or Cint(page) < 1 then
page = 1
elseif Cint(page) > allPages then
page = allPages
end if
rs.AbsolutePage = page
Do while not rs.eof and pages > 0 %>
这里输出你要的内容………………
<% pages = pages - 1
rs.MoveNext
Loop
else
Response.Write("数据库暂无内容!")
End if
rs.Close
Set rs = Nothing %>
我用过好多次了,无限好用!