怎样最有效的实现翻页?

mzybbs 2000-07-17 07:46:00
我想实现[ 最前页 ] [ 上一页 ] [ 下一页 ] [ 最末页 ],用什么方法好了??谢谢!
...全文
487 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzybbs 2000-08-08
  • 打赏
  • 举报
回复
谢谢大家!!谢谢。
qiujoe 2000-08-08
  • 打赏
  • 举报
回复
方法有七种,去chinaasp.com的文章去看看
华南虎哥 2000-07-19
  • 打赏
  • 举报
回复
下面一段代码也比较适合你的味口,不凡试一试:
————————————————————————————————————
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<!--#include virtual="/ADOVBS.inc"-->
<%
'设置你一页要显示多少记录
Const NumPerPage = 10

'取得当前所在页
Dim CurPage
If Request.QueryString("CurPage") = "" then
CurPage = 1 'We're on the first page
Else
CurPage = Request.QueryString("CurPage")
End If

Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=MyDB"


Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")

'设置游标属性
rs.CursorLocation = adUseClient

'设置缓存大小 = 每页需显示的记录数目
rs.CacheSize = NumPerPage

Dim strSQL
strSQL = "SELECT Name,Salary FROM Employee ORDER BY Name"
rs.Open strSQL, Conn

rs.MoveFirst
rs.PageSize = NumPerPage

'计算最多有多少页
Dim TotalPages
TotalPages = rs.PageCount

rs.AbsolutePage = CurPage

Dim count
%>

<HTML>
<BODY>
<B>姓名 - 薪水</B><BR>
<%
Count = 0
Do While Not rs.EOF And Count < rs.PageSize
Response.Write(rs("Name") & " - " & rs("Salary") & "<BR>")
Count = Count + 1
rs.MoveNext
Loop

Response.Write("第 " & CurPage & " 页,共 " & TotalPages & "页<P>")

'显示 Next / Prev 按钮
if CurPage > 1 then
Response.Write("<INPUT TYPE=BUTTON VALUE=PREV
ONCLICK=""document.location.href='thisfile.asp?curpage=" & curpage - 1
& "';"">")
End If

if CInt(CurPage) <> CInt(TotalPages) then
Response.Write("<INPUT TYPE=BUTTON VALUE=NEXT
ONCLICK=""document.location.href='thisfile.asp?curpage=" & curpage + 1
& "';"">")
End If

%>

</BODY>
</HTML>
—————————————————————————————————————
如果有问题,EMAIL:hblinux@163.net
Tyro 2000-07-19
  • 打赏
  • 举报
回复
那并没有什么错呀!
mzybbs 2000-07-19
  • 打赏
  • 举报
回复
没有。。
VictorYu 2000-07-18
  • 打赏
  • 举报
回复
可以呀,不过不知道为什么,PageCount不好用了
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title> Web Posting Information </title>
<object classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" id="info" ondatasetcomplete="nCount = this.recordset.PageCount;">
<param NAME="UseHeader" VALUE="True">
<param NAME="DataURL" VALUE="temp.csv">
</object>
<script>
var nCount;
var nIndex = 1;

function pagechange(flag)
{
if(flag == 0)
{
temptable.nextPage();
nIndex ++;
}
else
{
temptable.previousPage();
nIndex --;
}

if(nIndex == nCount)
{
down.disabled = true;
}
else
down.disabled = false;

if(nIndex == 1)
up.disabled = true;
else
up.disabled = false;
}

</script>
</head>
<body>
<TABLE DATASRC="#info" DATAPAGESIZE=1 id=temptable>
<TR>
<TD><INPUT TYPE=TEXTBOX DATAFLD="name">
</tr>
</TABLE>
<input value="下一页" type="button" onclick="pagechange(0);" id=down>
<input value="上一页" type="button" onclick="pagechange(1)" disabled id=up>
</body>
</html>


temp.csv
index:int, name:string
1,abc1
2,abc2
3,abc3
4,abc4
5,abc5
6,abc6
7,abc7
8,abc8
9,abc9
10,abc10
11,abc11
12,abc12
13,abc13
14,abc14
15,abc15
17,abc16
18,abc17
19,abc18
20,abc29
21,abc20
22,abc21
23,abc22
24,abc23
25,abc24
26,abc25
27,abc26
28,abc27
29,abc28



mzybbs 2000-07-18
  • 打赏
  • 举报
回复
ghj1976,Tyro谢谢,谢谢!
又一麻烦PageSize=1时怎么不管用,是不是不能小于Default 10?

谢谢大家!
Tyro 2000-07-18
  • 打赏
  • 举报
回复
re:mzybbs
有page应该等于1却等于2的情况吗?
Tyro 2000-07-18
  • 打赏
  • 举报
回复
把Page改为clng(Page)
蝈蝈俊 2000-07-18
  • 打赏
  • 举报
回复
tblstate.Open tmpSql,conn
改为:
tblstate.Open tmpSql,conn,3
肯定可以了
mzybbs 2000-07-18
  • 打赏
  • 举报
回复
我是测试的,我想让page在1,2之间变动。
蝈蝈俊 2000-07-18
  • 打赏
  • 举报
回复
呵呵呵呵:
rs.open sqlstring,conn,3
或 rs.open sqlstring,conn,2
才可以用 AbsolutePage 属性
rs.open sqlstring,conn,1
rs.open sqlstring,conn,0
是不可以的
Tyro 2000-07-18
  • 打赏
  • 举报
回复
re:mzybbs
那么你的page值到底是多少呀?
jinz 2000-07-18
  • 打赏
  • 举报
回复
同意zigzag的做法,我也是这样做的
mzybbs 2000-07-18
  • 打赏
  • 举报
回复
诸位壮士:我要请教的是 tblstate.AbsolutePage = Page为何错误!error message:
ADODB.Recordset error '800a0bb9'
应用程序使用的参数或者类型不正确,或者不在可以接受的范围之内,要不就是与其他数据冲突。
mzybbs 2000-07-18
  • 打赏
  • 举报
回复
我真碰到怪事了:why????

if Page = 0 then
Page = 1
end if
if Page > totalPage then
Page = totalPage
end if

之后,page 的值总为totalPage。
我的totalPage值是2,所以page值老为2.
zigzag 2000-07-18
  • 打赏
  • 举报
回复
不用在pagesize,pagecount上做文章,标准的做法是显示每页时都取出相同的记录集,根据页面参数中的页号和每页需要显示的记录数,算出应在记录集中移动的记录数,使用RECORDSET的MOVE方法移动相应的记录,然后显示一页。同样根据当前页号和总记录数在“上一页”,“下一页”等连接出加入页号参数。
Tyro 2000-07-18
  • 打赏
  • 举报
回复
看看你的page值是不是在什么地方被你改变了!
mzybbs 2000-07-18
  • 打赏
  • 举报
回复
我用的这句话为什么传不了page,即我点上一页时page值不变。。。
我把<%=Page-1%>改为N时还是page=1;
<A href="productor.asp?Search=<%=Search%>&FLSY=<%=FLSY%>&Page=<%=Page-1%>">上一页</font></a>
mzybbs 2000-07-17
  • 打赏
  • 举报
回复
谢谢诸君:我想这样做,出问题了 (应用程序使用的参数或者类型不正确,或者不在可以接受的范围之内,要不就是与其他数据冲突。36 line ) ?急

<html>
<%
flsy=request("FLSY")
search=request("search")

%>
<%
'先把页号取出
Page = Request("Page")
'如果是第一次,则页号为空值,再赋为1
if Page = "" then
Page = 1
end if
'查询记录
set conn=server.CreateObject("ADODB.connection")
conn.open "DSN=tanhao;uid=BizPortal;pwd=FgyZy0126"
set tblstate=Server.CreateObject("ADODB.Recordset")
Dim tmpSql
Dim tblstate

if flsy ="" then
tmpSql="select * FROM productor where productorname like '%" & search & "%'"
else
tmpSql="select * FROM productor where sshy like '%" & flsy & "%'"
end if
tblstate.Open tmpSql,conn
tblstate.PageSize = 10

'判断页号是否合法
if Page = 0 then
Page = 1
end if
if Page > tblstate.PageCount then
Page = tblstate.PageCount
end if
tblstate.AbsolutePage = Page
%>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>海外产品制造、代理商</title>
<style>
<!--
P {FONT-SIZE: 9pt; LINE-HEIGHT: 13pt}
TD {FONT-SIZE: 9pt; LINE-HEIGHT: 13pt}
.9p {FONT-SIZE: 9pt; LINE-HEIGHT: 13pt}
A:hover { color: rgb(0,128,255); text-decoration: underline }
A { color: rgb(0,0,0); text-decoration: none }
SELECT {FONT-SIZE: 9pt}
INPUT {FONT-SIZE: 9pt}
.14p {FONT-SIZE: 14px; LINE-HEIGHT: 18pt; WORD-SPACING: 2em}
-->
</style>
<script ID="clientEventHandlersJS" LANGUAGE="javascript">
<!--

function showdetail(pname)
{
window.location.href = "productorresult.asp?sproductno="+pname

}

//-->
</script>
</head>

<body topmargin="0" leftmargin="0">
<div align="center"><center>

<table border="0" width="770" cellspacing="0" cellpadding="6">
<tr>
<td width="36%"><p align="center"><img src="index.files/logo.gif" width="193" height="62"
alt="logo.gif (2484 字节)"></td>
<td width="64%"><img src="index.files/34932216.gif" width="468" height="60"
alt="34932216.gif (4938 字节)"></td>
</tr>
</table>
</center></div><div align="center"><center>

<table border="0" width="770" cellspacing="0" cellpadding="0">
<tr>
<td width="784"></td>
</tr>
<tr>
<td width="784" bgcolor="#000000" height="1"><img src="spacer.gif" width="1" height="1"
alt="spacer.gif (67 字节)"></td>
</tr>
<tr>
<td width="784"><div align="center"><center><table border="0" width="770" cellspacing="1"
cellpadding="0">
<tr>
<td width="130" align="center" bgcolor="#FFFFFF" valign="bottom"><img src="jt.gif"
width="7" height="7" alt="jt.gif (58 字节)">:::<a href="#">企业社区入口</a>:::</td>
<td width="357" align="center" bgcolor="#FFFFFF" valign="bottom"><font color="#000000"><p
align="left"></font>  <img src="jt.gif" width="7" height="7" alt="jt.gif (58 字节)">:::<a
href="#">sasasasas</a>:::</td>
</tr>
</table>
</center></div></td>
</tr>
<tr>
<td width="770" bgcolor="#000000" height="1"></td>
</tr>
</table>
</center></div><div align="center"><center>

<table border="0" width="770" cellspacing="0" cellpadding="0">
<tr>
<td width="139" bgcolor="#E1F0FF"></td>
<td width="1" rowspan="2" bgcolor="#000000"><img src="spacer.gif" width="1" height="1"
alt="spacer.gif (67 字节)"></td>
<td width="640" bgcolor="#4164A0" colspan="2"><table border="0" width="100%"
cellspacing="0" cellpadding="0">
<tr>
<td width="41%"><img src="index.files/edit.gif" width="18" height="15"
alt="edit.gif (166 字节)"><font color="#FFFFFF">关键词:<input maxLength="80"
name="_searchkey" size="8" style="border: 1px ridge rgb(0,0,0)">  <select name="_ss"
size="1" style="FONT-SIZE: 9pt">
<option value="zzs">制造商</option>
</select><select name="_ss" size="1" style="FONT-SIZE: 9pt">
<option value="gs">公司</option>
</select></font></td>
<td width="34%"><input type="radio" value="V1" checked name="R1"><font color="#FFFFFF">搜索所有分类<input
type="radio" value="V1" name="R1">仅在此行业下查询</font></td>
<td width="25%"><img src="index.files/ser1.gif" width="19" height="19"
alt="ser1.gif (321 字节)"><font color="#FFFFFF">查询</font></td>
</tr>
<tr>
<td width="100%" colspan="3" bgcolor="#000000" height="1"><font color="#FFFFFF"><img
src="spacer.gif" width="1" height="1" alt="spacer.gif (67 字节)"></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="139" bgcolor="#E1F0FF" valign="top"></td>
<td width="740" valign="top" colspan="2"><img src="index.files/icon_index.gif" width="32"
height="32" alt="icon_index.gif (670 字节)"><u><strong> 产 品 检 索 结 果 </strong></u><div
align="center"><center><table border="0" width="620">
<TBODY>
<tr>
<td width="459"></td>
<td width="153" valign="top"></td>
</tr>
<tr align="middle" vAlign="top">
<td width="459"><table bgColor="#fdf2f4" border="0" cellPadding="2" cellSpacing="0"
width="100%">
<TBODY>
<tr vAlign="top">
<td align="left"><b>  显示 1 - 20条 共 65条 </b></td>
<td align="right">[<a href="#"><font color="#ff9900"><A href="productor.asp?Search=<%=Search%>&FLSY=<%=FLSY%>&Page=1">最前页</font></a></a>] [<a href="#"><font
color="#ff9900"><A href="productor.asp?Search=<%=Search%>&FLSY=<%=FLSY%>&Page=<%=Page-1%>">上一页</font></a></a>] <a href="#">[<font color="#ff9900">下一页</font>]</a>
<a href="#">[<font color="#ff9900">最末页</font>] </a></td>
</tr>
</TBODY>
</table>
加载更多回复(4)

28,390

社区成员

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

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