以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML源码及示例(仅原创和转载) 』  (http://bbs.xml.org.cn/list.asp?boardid=32)
----  [原创]关于客户端分页显示的程序设计  (http://bbs.xml.org.cn/dispbbs.asp?boardid=32&rootid=&id=15891)


--  作者:acer2
--  发布时间:3/22/2005 1:53:00 AM

--  [原创]关于客户端分页显示的程序设计
大家好!最近正在学习关于XML的一些知识,在碰到客户端分页显示时,在网上寻找了很多资料,本论坛也有很多例子,但我由于水平有限,无法阅读下去,太繁琐了!后看了一个翻页例子,每次显示一条记录的,在本地操作的,可添加记录的(忘记是什么例子了),深受启发,于是自己写了一个分页小程序,在本地用HTM格式即可实现,在服务器则要用ASP实现,请大家给一下意见,谢谢!

<html>
<head>
<title>数据岛中的记录集</title>
</head>

<body bkcolor="#EEEEEE" text="blue">
<XML id="sjd">
<!-- #include file="vvv.asp" -->    '远程数据岛,通过查询获取数据,本地可用XML等
</xml>
<div id="xsqy"></div>
<script language="vbscript">
xyy 0 '第一次显示
function xyy(ys)
    sjd.recordset.movefirst
    if ys<0 then ys=0 '过头
    if ys>=sjd.recordset.RecordCount then ys=sjd.recordset.RecordCount-10 '过尾
    sjd.recordset.move ys
    xs="<table border=1>"
     for i=1 to 10
                  xs=xs&"<tr>"
                  xs=xs&"<td>"&sjd.recordset(0).value&"</td>"
                  xs=xs&"<td>"&sjd.recordset(1).value&"</td>"
                  xs=xs&"<td>"&sjd.recordset(2).value&"</td>"
                  if sjd.recordset.eof then exit for
                  sjd.recordset.movenext
                  xs=xs&"</tr>"
    next
    xs=xs&"</table>"
    xs=xs&"<input type=button onclick=xyy(0) value='首页'></input>"
    xs=xs&"<input type=button onclick=xyy("& ys-10 & ") value='上页'></input>"
    xs=xs&"<input type=button onclick=xyy("& ys+10 & ") value='下页'></input>"
    xs=xs&"<input type=button onclick=xyy("& sjd.recordset.RecordCount-10 & ") value='末页'></input>"
    xsqy.innerHTML=xs '更新显示
end function
</script>

</body>

</html>

以上小程序默认分页条数为10条,显示三个字段。在本地执行很正常,数据岛的设置可用<xml id="sjd" src="filename"></xml>,但上了服务器却说“对象关闭不能执行recordset的操作”,非要将数据岛嵌入HTML或ASP里才能正常操作,所以上面用了<!-- #include file -->。请大家批评指正!


[此贴子已经被作者于2005-3-22 11:48:48编辑过]

--  作者:acer2
--  发布时间:3/22/2005 9:22:00 PM

--  
经测试,还可用recordset.AbsolutePage等进行定位,使程序更易读。

<html>
<head>
<title>数据岛中的记录集</title>
</head>

<body bkcolor="#EEEEEE" text="blue">
<XML id="sjd">
<!-- #include file="vvv.xml" -->
</xml>
<div id="xsqy"></div>
<script language="vbscript">
xyy 1 '第一次显示从第1页开始
function xyy(ys)
    'sjd.recordset.sort="xm" 可惜这句不能执行,否则还能排序呢!
    if ys<1 then ys=1 '过头
    if ys>=sjd.recordset.pageCount then ys=sjd.recordset.pageCount-1 '过尾
    sjd.recordset.AbsolutePage=ys 
    xs="<table border=1>"
     for i=1 to sjd.recordset.pagesize
                  xs=xs&"<tr>"
                  xs=xs&"<td>"&sjd.recordset(0).value&"</td>"
                  xs=xs&"<td>"&sjd.recordset(1).value&"</td>"
                  xs=xs&"<td>"&sjd.recordset(2).value&"</td>"
                  if sjd.recordset.eof then exit for
                  sjd.recordset.movenext
                  xs=xs&"</tr>"
    next
    xs=xs&"</table>"
    xs=xs&"<input type=button onclick=xyy(1) value='首页'></input>"
    xs=xs&"<input type=button onclick=xyy("& ys-1 & ") value='上页'></input>"
    xs=xs&"<input type=button onclick=xyy("& ys+1 & ") value='下页'></input>"
    xs=xs&"<input type=button onclick=xyy("& sjd.recordset.pageCount-1 & ") value='末页'></input>"
    xsqy.innerHTML=xs '更新显示
end function
</script>

</body>

</html>

pagesize默认是10,改为其它即可改变每页显示条数。


--  作者:Qr
--  发布时间:3/23/2005 9:38:00 AM

--  
不错,学习!
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms