ASP用JAVASCRIPT脚本实现分页的办法
时间:2007-10-30 13:18:00
asp分页做为一个经典的asp问题,有着非常丰富的分页形式和分页方法,但是大多数的asp分页都是使用VBscript作为服务器端的脚本,本文介绍了一种使用javascript脚本来处理asp服务器端的分页方法,感兴趣的朋友可以看看。
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<!--#include file="connect.asp"-->
<!--#include file="news.asp"-->
<%
var DataSet,sql,DataList;
var i=0;
var j=0;
DataList=new News();
DataSet=Server.CreateObject("Adodb.recordset");
sql="select * from News where ngroup='集团新闻' order by id desc";
DataSet.Open(sql,DataConn,1,1);
//是否有数据
if ((DataSet.eof)&&(DataSet.bof))
{
Response.Write("<BR>" );
Response.Write("=== 暂无 ===");
Response.Write("<BR><BR>");
Response.End();
}
//记录总数
NumRecords=DataSet.RecordCount;
//设定每页最大记录数
PageSize=3;
//总页数
NumPages=Math.ceil(NumRecords/PageSize);
//当前页
i=Request.QueryString("CurrentPageID").Count;
if (i==0)
{
CurrentPageID=1;
}
else
{
CurrentPageID=parseInt(Request.QueryString("CurrentPageID"));
}
//初始化
PreviousPageID=CurrentPageID-1;
NextPageID=CurrentPageID+1;
HomePage=1;
EndPage=NumPages;
//内容列表
DataSet.MoveFirst;
DataSet.Move((CurrentPageID-1)*PageSize,1);
while (!DataSet.eof && j<PageSize)
{
Response.Write("<a href=show.asp?id="+DataSet("id")+" target=\"_blank\">"+DataSet("subject")+"</a><br>");
j=j+1;
DataSet.MoveNext;
}
//设定URL
if (CurrentPageID == HomePage)
{
Response.Write("<p class='Normal'><a href=list.asp?CurrentPageID="+HomePage+">首页</a> ");
Response.Write("上一页 ");
Response.Write("<a href=list.asp?CurrentPageID="+NextPageID+">下一页</a> ");
Response.Write("<a href=list.asp?CurrentPageID="+EndPage+">尾页</a> </p>");
}
else if (CurrentPageID == EndPage)
{
Response.Write("<p class='Normal'><a href=list.asp?CurrentPageID="+HomePage+">首页</a> ");
Response.Write("<a href=list.asp?CurrentPageID="+PreviousPageID+">上一页</a> ");
Response.Write("下一页 ");
Response.Write("<a href=list.asp?CurrentPageID="+EndPage+">尾页</a> </p>");
}
else
{
Response.Write("<p class='Normal'><a href=list.asp?CurrentPageID="+HomePage+">首页</a> ");
Response.Write("<a href=list.asp?CurrentPageID="+PreviousPageID+">上一页</a> ");
Response.Write("<a href=list.asp?CurrentPageID="+NextPageID+">下一页</a> ");
Response.Write("<a href=list.asp?CurrentPageID="+EndPage+">尾页</a> </p>");
}
%>
相关阅读:
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
技巧/诀窍:在ASP.NET中重写URL
![](https://img.aspxhome.com/file/UploadPic/20079/23/2007923122811285s.jpg)
不要忽略了颜色的可用性
![](https://img.aspxhome.com/file/UploadPic/20093/5/01-24s.jpg)
有感用户体验规划与系统实现
![](https://img.aspxhome.com/file/UploadPic/200911/27/01-48s.jpg)
网页设计进阶之一 (步骤和大局观)
在生成的静态页面中统计点击次数
良好体验,必须是全方位的
![](https://img.aspxhome.com/file/UploadPic/20099/24/15-37s.png)
Oracle数据库的备份及恢复策略研究
解析SQL Server中数据库快照的工作原理
解读MySQL的InnoDB引擎日志工作原理
css中的类和伪类
CSS 针对 Safari(WebKit)的 CSS 注意事项 3
写给JavaScript库开发者们的规则
保护SQL服务器的安全 用户识别问题
![](https://img.aspxhome.com/file/UploadPic/200812/20081225122629996.jpg)
ASP在服务器自动解压RAR文件
由黄钻等级图标处理引发的思考
![](https://img.aspxhome.com/file/UploadPic/200911/16/20091116124056484s.jpg)
用javascript实现Base64编码
SQL优化基础 使用索引(一个小例子)
![](https://img.aspxhome.com/file/UploadPic/20121/29/2012129183226601s.png)
从Vista地址栏到网站导航菜单
![](https://img.aspxhome.com/file/UploadPic/20099/8/nav-62s.jpg)
Javascript: 为<input>设置readOnly属性问题,希望大家以后要小心
IE6,IE7中定位相关的怪异问题
![](https://img.aspxhome.com/file/UploadPic/200912/8/position_demo1-45s.png)