网络编程
位置:首页>> 网络编程>> Asp编程>> 仿google的asp分页代码

仿google的asp分页代码

  发布时间:2009-03-08 18:27:00 

标签:google,分页,ajax

仿google的asp分页代码index.asp(文件1)


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!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>pages</title>
<script type="text/javascript" src="ajaxrequest.js"></script>
<script type="text/javascript">
function getResponse(url,container){
      var ajax=new AJAXRequest;
   ajax.setcharset("gb2312");
      ajax.get(url,function(obj){ document.getElementById(container).innerHTML=obj.responseText; });
}
</script>
<style type="text/css">
div.pagebar {
font-size: 12px;
padding: 1px;
}
div.pagebar a {
     display: inline;
padding: 2px 5px 0 5px;
margin-right: 3px;
border-width: 1px;
border-style: solid;
border-color: #f5f5f5 #ccc #ccc #f5f5f5;
background-color: #f8f8f8;
text-decoration: none;
color: #06c;
}
div.pagebar a:hover, span.nopage {
     display: inline;
padding: 2px 5px 0 5px;
margin-right: 3px;
border-width: 1px;
border-style: solid;
border-color: #09c #036 #036 #09c;
background-color: #06c;
color: #eee;
cursor: default;
}
div.pagebar a:hover {
     cursor: pointer;
}
</style>
</head>

<body>
<div id="news">
<!--#include file="msnshow2.asp"--></div></body>
</html>


红色部分有个标记div为传递到pageClass.asp使用






仿google的asp分页代码msnshow2.asp(文件2)


<!--#include file="conn.asp"-->
<!--#include file="pageClass.asp"-->
<%
response.Charset = "gb2312"
'#############类调用样例#################
'创建对象
Set mypage=new xdownpage
'得到数据库连接
mypage.getconn=conn
'sql语句
mypage.getsql="select * from feedback order by id desc"
'设置每一页的记录条数据为2条
mypage.pagesize = 5
mypage.pageNum = 5
'返回Recordset
set rs=mypage.getrs()

dim thePage
thePage = Request.QueryString("page")
if thePage = empty or thePage = "" then thePage = 1

'显示数据
Response.Write("<ul>")
for i=1 to mypage.pagesize
'这里就可以自定义显示方式了
if not rs.eof then
%>
<tr HEIGHT="26">
<td width="100%" height="30" align="center"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#bbbbbb" class="tableborder">
<tr>
<td style="word-break:break-all;"> <table width="100%" height="31" border="0" cellpadding="4" cellspacing="0" bgcolor="#00508d">
<tr class="biggreentext">
<td width="18%"> <%=rs("UserName")%></td>
<td><%=rs("userzhuti")%>  [<%=cstr(rs("Postdate"))%>]</td>
</tr>
</table></td>
</tr>
<tr>
<td height="24"> <table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#336699">
<tr>
<td height="24" style="word-break:break-all;"><%=rs("Comments")%></td>
</tr>
</table></td>
</tr>
<tr>
<td height="24" style="word-break:break-all;"> <table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#336699">
<tr>
<td width="18%" height="24"> <div align="center" class="englishtext2"><font color="#ffffff"><strong>Reply:</strong></font></div></td>
<td width="82%" class="englishtext2"> <font color="#ffffff"><%=rs("Replay")%>
[<%=rs("ReplayDate")%>] </font> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="17"></td>
</tr>
<%
rs.movenext
else
exit for
end if
next

Response.Write("</ul>")

'显示分页信息,这个方法可以,在set rs=mypage.getrs()以后,可在任意位置调用,可以调用多次
mypage.showpage()
%>




仿google的asp分页代码pageClass.asp(文件3)

<%
'===================================================================
'XDOWNPAGE ASP版本
'版本 1.00
'Code by zykj2000
'Email: zykj_2000@163.net
'BBS: http://bbs.513soft.net
'本程序可以免费使用、修改,希望我的程序能为您的工作带来方便
'但请保留以上请息
'
'Modified by 7thpark
'Blog: http://log.7thpark.com
'基于原作者的分页类进行了修改:
'1.当前页不显示链接
'2.解决了地址栏累加为题
'3.去掉了第一页时上一页跟首页,及最后一页时下一页跟尾页
'4.添加了pageNum属性,即每页可以显示的页码链接的数量
'5.加入了ajax,无刷新分页读取,同时无刷新读取信息内容
'
'程序特点
'本程序主要是对数据分页的部分进行了封装,而数据显示部份完全由用户自定义,
'支持URL多个参数
'
'使用说明
'程序参数说明
'PapgeSize 定义分页每一页的记录数
'GetRS 返回经过分页的Recordset此属性只读
'GetConn 得到数据库连接
'GetSQL 得到查询语句
'程序方法说明
'ShowPage 显示分页导航条,唯一的公用方法
'
'===================================================================
Const Btn_First="首页" '定义第一页按钮显示样式
Const Btn_Prev="上一页" '定义前一页按钮显示样式
Const Btn_Next="下一页" '定义下一页按钮显示样式
Const Btn_Last="尾页" '定义最后一页按钮显示样式
Const XD_Align="Center" '定义分页信息对齐方式
Const XD_Width="100%" '定义分页信息框大小

Class Xdownpage
Private XD_PageCount,XD_Conn,XD_Rs,XD_SQL,XD_PageSize,Str_errors,int_curpage,str_URL,int_totalPage,int_totalRecord,XD_sURL,p_pageNum


'=================================================================
'PageSize 属性
'设置每一页的分页大小
'=================================================================
Public Property Let PageSize(int_PageSize)
If IsNumeric(Int_Pagesize) Then
XD_PageSize=CLng(int_PageSize)
Else
str_error=str_error & "PageSize的参数不正确"
ShowError()
End If
End Property
Public Property Get PageSize
If XD_PageSize="" or (not(IsNumeric(XD_PageSize))) Then
PageSize=10
Else
PageSize=XD_PageSize
End If
End Property

'=================================================================
'pageNum 属性
'设置每一页的页码数目
'=================================================================
Public Property Let pageNum(int_pageNum)
If IsNumeric(int_pageNum) Then
p_pageNum=CLng(int_pageNum)
Else
str_error=str_error & "pageNum的参数不正确"
ShowError()
End If
End Property
Public Property Get pageNum
If p_pageNum="" or (not(IsNumeric(p_pageNum))) Then
pageNum=10
Else
pageNum=p_pageNum
End If
End Property


'=================================================================
'GetRS 属性
'返回分页后的记录集
'=================================================================
Public Property Get GetRs()
Set XD_Rs=Server.createobject("adodb.recordset")
XD_Rs.PageSize=PageSize
XD_Rs.Open XD_SQL,XD_Conn,1,1
If not(XD_Rs.eof and XD_RS.BOF) Then
If int_curpage>XD_RS.PageCount Then
int_curpage=XD_RS.PageCount
End If
XD_Rs.AbsolutePage=int_curpage
End If
Set GetRs=XD_RS
End Property

'================================================================
'GetConn 得到数据库连接
'
'================================================================
Public Property Let GetConn(obj_Conn)
Set XD_Conn=obj_Conn
End Property

'================================================================
'GetSQL 得到查询语句
'
'================================================================
Public Property Let GetSQL(str_sql)
XD_SQL=str_sql
End Property


'==================================================================
'Class_Initialize 类的初始化
'初始化当前页的值
'
'==================================================================
Private Sub Class_Initialize
'========================
'设定一些参数的黙认值
'========================
XD_PageSize=10 '设定分页的默认值为10
'========================
'获取当前面的值
'========================
If request("page")="" Then
int_curpage=1
ElseIf not(IsNumeric(request("page"))) Then
int_curpage=1
ElseIf CInt(Trim(request("page")))<1 Then
int_curpage=1
Else
Int_curpage=CInt(Trim(request("page")))
End If

End Sub

'====================================================================
'ShowPage 创建分页导航条
'有首页、前一页、下一页、末页、还有数字导航
'
'====================================================================
Public Sub ShowPage()
Dim str_tmp
XD_sURL = GetUrl()
int_totalRecord=XD_RS.RecordCount
If int_totalRecord<=0 Then
str_error=str_error & "总记录数为零,请输入数据"
Call ShowError()
End If
If int_totalRecord="" then
int_TotalPage=1
Else
If int_totalRecord mod PageSize =0 Then
int_TotalPage = Int(int_TotalRecord / XD_PageSize)
Else
int_TotalPage = Int(int_TotalRecord / XD_PageSize) + 1
End If
End If

If Int_curpage>int_Totalpage Then
int_curpage=int_TotalPage
End If

'==================================================================
'显示分页信息,各个模块根据自己要求更改显求位置
'==================================================================
response.write "<div class=""pagebar"">"
str_tmp=ShowFirstPrv
response.write str_tmp
str_tmp=showNumBtn
response.write str_tmp
str_tmp=ShowNextLast
response.write str_tmp
str_tmp=ShowPageInfo
response.write str_tmp
response.write "</div>"
End Sub

'====================================================================
'ShowFirstPrv 显示首页、前一页
'
'
'====================================================================
Private Function ShowFirstPrv()
Dim Str_tmp,int_prvpage
If int_curpage=1 Then
'str_tmp=Btn_First&" "&Btn_Prev
str_tmp=""
Else
int_prvpage=int_curpage-1
str_tmp="<a href=""javascript:void(0)"" onclick=""getResponse('"&XD_sURL & "1" & "','news')"">" & Btn_First&"</a><a href=""javascript:void(0)"" onclick=""getResponse('" & XD_sURL & CStr(int_prvpage) & "','news')"">" & Btn_Prev&"</a>"
End If
ShowFirstPrv=str_tmp
End Function

'====================================================================
'ShowNextLast 下一页、末页
'
'
'====================================================================
Private Function ShowNextLast()
Dim str_tmp,int_Nextpage
If Int_curpage>=int_totalpage Then
'str_tmp=Btn_Next & " " & Btn_Last
str_tmp=""
Else
Int_NextPage=int_curpage+1
str_tmp="<a href=""javascript:void(0)"" onclick=""getResponse('" & XD_sURL & CStr(int_nextpage) & "','news')"">" & Btn_Next&"</a><a href=""javascript:void(0)"" onclick=""getResponse('"& XD_sURL & CStr(int_totalpage) & "','news')"">" & Btn_Last&"</a>"
End If
ShowNextLast=str_tmp
End Function


'====================================================================
'ShowNumBtn 数字导航
'
'
'====================================================================
Private Function showNumBtn()
Dim i,str_tmp
Dim sliceNum, sliceCount
sliceNum = Int(int_curpage/pageNum)
sliceCount = Int(int_totalpage/pageNum)
if int_curpage mod pageNum = 0 then
for i=(sliceNum-1)*pageNum+1 to sliceNum*pageNum
if int_curpage = i then
str_tmp=str_tmp & "<span class=""nopage"">"&i&"</span>"
else
str_tmp=str_tmp & "<a href=""javascript:void(0)"" onclick=""getResponse('" & XD_sURL & CStr(i) & "','news')"">"&i&"</a>"
end if
next
else
if sliceNum=sliceCount then
for i=sliceCount*pageNum+1 to int_totalpage
if int_curpage = i then
str_tmp=str_tmp & "<span class=""nopage"">"&i&"</span>"
else
str_tmp=str_tmp & "<a href=""javascript:void(0)"" onclick=""getResponse('" & XD_sURL & CStr(i) & "','news')"">"&i&"</a>"
end if
next
else
for i=sliceNum*pageNum+1 to (sliceNum+1)*pageNum
if int_curpage = i then
str_tmp=str_tmp & "<span class=""nopage"">"&i&"</span>"
else
str_tmp=str_tmp & "<a href=""javascript:void(0)"" onclick=""getResponse('" & XD_sURL & CStr(i) & "','news')"">"&i&"</a>"
end if
next
end if
end if

showNumBtn=str_tmp
End Function


'====================================================================
'ShowPageInfo 分页信息
'更据要求自行修改
'
'====================================================================
Private Function ShowPageInfo()
Dim str_tmp
str_tmp="<span class=""nopage"">页次:"&int_curpage&"/"&int_totalpage&"页 共"&int_totalrecord&"条记录 "&XD_PageSize&"条/每页</span>"
ShowPageInfo=str_tmp
End Function
'==================================================================
'GetURL 得到当前的URL
'更据URL参数不同,获取不同的结果
'
'==================================================================
Private Function GetURL()
Dim strurl,str_url,i,j,search_str,result_url
search_str="page="

strurl=Request.ServerVariables("URL")
Strurl=split(strurl,"/")
i=UBound(strurl,1)
str_url=strurl(i)'得到当前页文件名

str_params=Trim(Request.ServerVariables("QUERY_STRING"))
If str_params="" Then
result_url=str_url & "?page="
Else
If InstrRev(str_params,search_str)=0 Then
result_url=str_url & "?" & str_params &"&page="
Else
j=InstrRev(str_params,search_str)-2
If j=-1 Then
result_url=str_url & "?page="
Else
str_params=Left(str_params,j)
result_url=str_url & "?" & str_params &"&page="
End If
End If
End If
GetURL=result_url
End Function

'====================================================================
' 设置 Terminate 事件。
'
'====================================================================
Private Sub Class_Terminate
XD_RS.close
Set XD_RS=nothing
End Sub
'====================================================================
'ShowError 错误提示
'
'
'====================================================================
Private Sub ShowError()
If str_Error <> "" Then
Response.Write("" & str_Error & "")
Response.End
End If
End Sub
End class
%>




仿google的asp分页代码ajaxrequest.js(文件4)


/*------------------------------------------
Name: AJAXRequest
Author: xujiwei
Website: http://www.xujiwei.cn
E-mail: vipxjw@163.com
Copyright (c) 2007, All Rights Reserved

AJAXRequest Deveoper Manual:
http://www.xujiwei.cn/works/ajaxrequest/
------------------------------------------*/
function AJAXRequest() {
var xmlPool=new Array,AJAX=this,ac=arguments.length,av=arguments;
var xmlVersion = ["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
var nullfun=function(){return;};
var av=ac>0?typeof(av[0])=="object"?av[0]:{}:{};
var encode=av.charset?av.charset.toUpperCase()=="UTF-8"?encodeURIComponent:escape:encodeURIComponent;
this.url=av.url?av.url:"";
this.oncomplete=av.oncomplete?av.oncomplete:nullfun;
this.content=av.content?av.content:"";
this.method=av.method?av.method:"POST";
this.async=av.async?async:true;
this.onexception=av.onexception?av.exception:nullfun;
this.ontimeout=av.ontimeout?av.ontimeout:nullfun;
this.timeout=av.timeout?av.timeout:3600000;
if(!getObj()) return false;
function getObj() {
var i,tmpObj;
for(i=0;i<xmlPool.length;i++) if(xmlPool[i].readyState==0wswsxmlPool[i].readyState==4) return xmlPool[i];
try { tmpObj=new XMLHttpRequest; }
catch(e) {
for(i=0;i<xmlVersion.length;i++) {
try { tmpObj=new ActiveXObject(xmlVersion[i]); } catch(e2) { continue; }
break;
}
}
if(!tmpObj) return false;
else { xmlPool[xmlPool.length]=tmpObj; return xmlPool[xmlPool.length-1]; }
}
function $(id) { return document.getElementById(id); }
function varobj(val) {
if(typeof(val)=="string") {
if(val=$(val)) return val;
else return false;
}
else return val;
}
this.setcharset=function(cs) {
if(cs.toUpperCase()=="UTF-8") encode=encodeURIComponent;
else encode=escape;
}
this.send=function() {
var purl,pc,pcbf,pm,pa,ct,ctf=false,xmlObj=getObj(),ac=arguments.length,av=arguments;
if(!xmlObj) return false;
purl=ac>0?av[0]:this.url;
pc=ac>1?av[1]:this.content;
pcbf=ac>2?av[2]:this.oncomplete;
pm=ac>3?av[3].toUpperCase():this.method;
pa=ac>4?av[4]:this.async;
if(!pmwsws!purlwsws!pa) return false;
var ev={url:purl, content:pc, method:pm};
purl+=(purl.indexOf("?")>-1?"&":"?")+Math.random();
xmlObj.open(pm,purl,pa);
if(pm=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ct=setTimeout(function(){ctf=true;xmlObj.abort();},AJAX.timeout);
xmlObj.onreadystatechange=function() {
if(ctf) AJAX.ontimeout(ev);
else if(xmlObj.readyState==4) {
ev.status=xmlObj.status;
try{ clearTimeout(ct); } catch(e) {};
try{
if(xmlObj.status==200) pcbf(xmlObj);
else AJAX.onexception(ev);
}
catch(e) { AJAX.onexception(ev); }
}
}
if(pm=="POST") xmlObj.send(pc); else xmlObj.send("");
}
this.get=function() {
var purl,pcbf,ac=arguments.length,av=arguments;
purl=ac>0?av[0]:this.url;
pcbf=ac>1?av[1]:this.oncomplete;
if(!purl&&!pcbf) return false;
this.send(purl,"",pcbf,"GET",true);
}
this.update=function() {
var purl,puo,pinv,pcnt,rinv,ucb,ac=arguments.length,av=arguments;
puo=ac>0?av[0]:null;
purl=ac>1?av[1]:this.url;
pinv=ac>2?(isNaN(parseInt(av[2]))?1000:parseInt(av[2])):null;
pcnt=ac>3?(isNaN(parseInt(av[3]))?null:parseInt(av[3])):null;
if(puo=varobj(puo)) {
ucb=function(obj) {
var nn=puo.nodeName.toUpperCase();
if(nn=="INPUT"wswsnn=="TEXTAREA") puo.value=obj.responseText;
else try{puo.innerHTML=obj.responseText;} catch(e){};
}
}
else ucb=nullfun;
if(pinv) {
AJAX.send(purl,"",ucb,"GET",true);
if(pcnt&&--pcnt) {
var cf=function(cc) {
AJAX.send(purl,"",ucb,"GET",true);
if(cc<1) return; else cc--;
setTimeout(function(){cf(cc);},pinv);
}
setTimeout(function(){cf(--pcnt);},pinv);
}
else return(setInterval(function(){AJAX.send(purl,"",ucb,"GET",true);},pinv));
}
else this.send(purl,"",ucb,"GET",true);
}
this.post=function() {
var purl,pcbf,pc,ac=arguments.length,av=arguments;
purl=ac>0?av[0]:this.url;
pc=ac>1?av[1]:"";
pcbf=ac>2?av[2]:this.oncomplete;
if(!purl&&!pcbf) return false;
this.send(purl,pc,pcbf,"POST",true);
}
this.postf=function() {
var fo,pcbf,purl,pc,pm,ac=arguments.length,av=arguments;
if(!(fo=ac>0?av[0]:null)) return false;
if(fo=varobj(fo)) {
if(fo.nodeName!="FORM") return false;
}
else return false;
pcbf=ac>1?av[1]:this.oncomplete;
purl=ac>2?av[2]:(fo.action?fo.action:this.url);
pm=ac>3?av[3]:(fo.method?fo.method.toUpperCase():"POST");
if(!pcbf&&!purl) return false;
pc=this.formToStr(fo);
if(!pc) return false;
if(pm) {
if(pm=="POST") this.send(purl,pc,pcbf,"POST",true);
else if(purl.indexOf("?")>0) this.send(purl+"&"+pc,"",pcbf,"GET",true);
else this.send(purl+"?"+pc,"",pcbf,"GET",true);
}
else this.send(purl,pc,pcbf,"POST",true);
}
/* formToStr
// from SurfChen <surfchen@gmail.com>
// @url http://www.surfchen.org/
// @license http://www.gnu.org/licenses/gpl.html GPL
// modified by xujiwei
// @url http://www.xujiwei.cn/
*/
this.formToStr=function(fc) {
var i,qs="",and="",ev="";
for(i=0;i<fc.length;i++) {
e=fc[i];
if (e.name!='') {
if (e.type=='select-one'&&e.selectedIndex>-1) ev=e.options[e.selectedIndex].value;
else if (e.type=='checkbox' wsws e.type=='radio') {
if (e.checked==false) continue;
ev=e.value;
}
else ev=e.value;
ev=encode(ev);
qs+=and+e.name+'='+ev;
and="&";
}
}
return qs;
}
}



仿google的asp分页代码conn.asp(文件5)

<%
set conn = server.CreateObject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq=" & server.Mappath("page.mdb")
%>

0
投稿

猜你喜欢

  • 和大多数的语言脚本一样,学习ASP最好的方法就是亲身尝试ASP,使用你自己的系统安装PWS或者IIS。你可以边学习边在你自己的服务器上测试A
  • 在web开发中常常要使用js,为了提高效率一般都会制作js的类文件。这样在使用中更新复用都很方便。下面按照我工作中的一个案例,介绍如何定义j
  • 任何熟悉SQL和关系数据库的人都遇见过大量的连接类型。最简单的说,连接(join)会把两个表的内容组合到一个虚拟表或者recordset内。
  • 当列表菜单项目特别多的时候,使用JavaScript手风琴菜单(Accordion Menus)是个不错的选择。手风琴折叠菜单利于组织菜单项
  • SqlBulkCopy 来自数据源的 String 类型的给定值不能转换为指定目标列的类型 nvarchar。 在网上找了下,大都说是因为数
  • 如何用下拉列表显示数据库里的内容? 我们来看看实现这个功能的程序:<%Dim objDC, objRSS
  • 随着WEB标准在国内的不断普及,结构表现行为分离、模块化、语义化、优雅退化等概念也成为考核一名前端人员对WEB标准理解的重要条目,其中,由于
  • 1. @@rowcount: 获取受影响行数 代码如下:update SNS_TopicData set TopicCount=TopicC
  • 还有种片面的观点认为,做网站设计与平面差不多,比如老罗发布的这则招聘中提到:年薪十万招擅长做下列网站设计风格的平面设计师一名。在专业角度,网
  • asp连接sql 第一种写法: 代码如下: MM_conn_STRING = "Driver={SQL Server};serv
  • 最近有网友在留言板里问到jRaiser和jQuery的冲突问题,特此写一篇文章进行解释。冲突的根源众所周知,jQuery是通过一个全局变量$
  • 内容摘要:本文是一篇实例讲解的文章。作为一个普通的程序员,我深知,一个优秀的例程,对于正在学习编程的人是多么的有帮助。本文中使用的例程,是一
  • 为什么要用flash呢?动画流畅,视觉效果好缓存能力强那使用flash有什么问题呢?需要Flash播放器在M$的补丁打遍天下之前IE有那神奇
  • 最近 W3C 一口气推出 7  个 HTML 工作草案,涵盖了 HTML5,HTML RDF,HTML Microdata,HTM
  • 作用域链(Scope Chain)JavaScript中的一种重要机制,JS中所有的标识符(Identifier)都是通过Scope Cha
  • 代码如下:function HTMLEncode(fString) fString=Replace(fString,&q
  • 说绘画语言,西方的油画是人类视觉语言里怎么也不能忽略的浓烈一笔。14~15世纪,蛋彩画——油画前身的发明,绘画可以使用均匀过渡的色彩渐变,并
  • Mysql默认是不可以通过远程机器访问的,通过下面的配置可以开启远程访问.我的Mysql环境是ubuntu+mysql51.修改/etc/m
  • 问:如何让内联框架里面的网页背景透明?(用iframe嵌套一网页,怎么能够设置其背景为透明以便能显示父框架中网页的背景图?)答:这是需要 I
  • DOM遍历基于ID、元素类型、类名查找元素非常有用,但是如果你想基于它在DOM树中的位置来查找元素该怎么办?换句话说,你有一个给定的元素,你
手机版 网络编程 asp之家 www.aspxhome.com