首页 | 心情日记 | 建站心得 | 编程技术 | 大盘分析 | 股市信息 | 学习园地 | 电脑技巧 | 物流外贸 | 另类其它 | 站长推荐 | 给我留言 | 相册

用户登陆
用户:
密码:
 
不保存保存一天
保存一月保存一年

站点日历
73 2024 - 3 48
     12
3456789
10111213141516
17181920212223
24252627282930
31


站点统计

最新评论

日志搜索

 标题   内容


一个简单易用的ASP分页代码 ASP实现地址栏加密和解密的函数
未知 ASP通用分页源代码   [ 日期:2010-01-15 00:35:40 ]   [ 来自:本站原创 ]

海外邮件中继,海外退信中继,美国高速VPS,不限流量VPN,邮局维护和管理,邮件网关,EMOS邮件中继,POSTFIX邮件中继,Winwebmail邮件中继,Winmail邮件中继,DBMail邮件中继,JDMail邮件中继,Exchange邮件中继,MDaemon邮件中继 淘宝店:http://shantan.taobao.com 云邮科技官网:www.yunrelay.com

【字体设置:
这个分页代码使用很简单,只有4个步骤: 
(1)构造 SQL 查询语句、设置数据库连接字符串、设置每页记录显示数目 
(2)插入分页控制代码 <b>navigator_init.inc</b> 文件 
(3)在页面的适当地方(即你想显示“上页、下页”的地方),插入分页导航代码 <b>navigator.inc</b> 
(4)用循环显示本页记录 

 

<一> 需要分页的 ASP 文件 

sample.asp 

<% 
' 取得当前 ASP 页面的完整路径,重要技巧 
theScript = Request.ServerVariables("SCRIPT_NAME") 

' (1)构造 SQL 语句 

myconnstr = "driver={SQL Server};server=yourserver;uid=sa;pwd=;database=yourdatabase" 
thePageSize = 20 ' 每页显示的记录数 

uSQL = "select * from yourtablename " 

' (2)插入分页控制代码 
%> 
<!--#include file="../inc/control/navigator_init.inc"--> 

<html> 
<head> 
<title>test</title> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<link rel="stylesheet" href="../../../../../default.css" type="text/CSS"> 
</head> 

<!-- 你的 HTML 代码//--> 

<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td> 
<!--(3)插入分页导航代码--> 
<!--#include file="../inc/control/navigator.inc"--> 
</td> 
</tr> 
</table> 

<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td> 
<!--(4)用循环显示本页记录--> 

<% For i = 1 To rs.pagesize %> 
<!-- 你的记录显示代码//--> 
<% 
rs.MoveNext 
If rs.EOF Then 
Exit For 
rs.close 
conn.close 
End If 
next 
%> 

</td> 
</tr> 
</table> 


</body> 
</html> 

 

<二> 分页控制代码: 

navigator_init.inc 

<% 
theCurrentPageNum = clng(request("pn")) 

' 用页面名字来唯一确定当前页面使用的 rs 
' 由于不同目录下面可以有相同名字的文件,因此使用带完整路径的文件名 
theCurrentRS = "rs" & theScript 

If theCurrentPageNum = 0 Then 

Set conn = Server.CreateObject("ADODB.Connection") 
conn.open myconnstr 
set rs = server.createobject("adodb.recordset") 
rs.open uSQL,conn,1,3 

if rs.recordcount > 0 then 
rs.PageSize = thePageSize 
rs.AbsolutePage = 1 
theCurrentPageNum = 1 
Set Session(theCurrentRS) = rs 
end if 

else 
Set rs = Session(theCurrentRS) 
if rs.recordcount > 0 then 
rs.AbsolutePage = theCurrentPageNum 
end if 
End If 

'构造导航条 

href_first = theScript & "?mo=0&pn=1" 
href_prev = theScript & "?mo=0&pn=" & (theCurrentPageNum-1) 
href_next = theScript & "?mo=0&pn=" & (theCurrentPageNum+1) 
href_last = theScript & "?mo=0&pn=" & rs.pagecount 

strnav_first= "<a href=../../../../" & href_first & ">首页</a>" 
strnav_prev = "<a href=../../../../" & href_prev & ">前页</a>" 
strnav_next = "<a href=../../../../" & href_next & ">后页</a>" 
strnav_last = "<a href=../../../../" & href_last & ">末页</a>" 

if rs.pagecount > 1 then 
'在首页 
if theCurrentPageNum = 1 then 
strnav_first= "首页" 
strnav_prev = "前页" 
end if 
'在末页 
if theCurrentPageNum = rs.pagecount then 
strnav_next = "后页" 
strnav_last = "末页" 
end if 
else 
strnav_first= "首页" 
strnav_prev = "前页" 
strnav_next = "后页" 
strnav_last = "末页" 
end if 

strnav = strnav_first & " " & strnav_prev & " " & strnav_next & " " & strnav_last 

' 由于在 listrecords 函数中,当显示完所有记录时将关闭 rs ,因此先把 rs.recordcount 保存起来 
theRsCount = rs.recordcount 
%> 

 


<三> 分页导航代码: 

navigator.inc 

<table width="300" border="0" align="right" cellpadding="0" cellspacing="0" height="30"> 
<form action="<%=theScript%>" method="post" name="form_nav" onsubmit="javascript:return checkpn(this);"> 
<tr> 
<td align="right"> 
<%=rs.recordcount%> 条 <%=rs.pagecount%>页 第<input type="text" name="pn" value="<% 
=theCurrentPageNum%>" size=2 maxlength=4 class="form_text_underline">页 <%= strnav %> 
</td> 
</tr> 
</form> 
</table> 
<script language="javascript"> 

// 判断用户输入的页码是否合法 

function checkpn(form) 

pn = form.pn ; 

if (pn.value=="") 
{ alert("请输入页码") ;pn.select();return false;} 

if (!uisNum(pn.value)) 
{ alert("页码是数字") ;pn.select();return false;} 

if (pn.value-<%=rs.pagecount%>>0) 
{ alert("页码不能大于<%=rs.pagecount%>") ;pn.select();return false;} 

return true; 


function aLength(str) 

var i,len; 
len=0; 
for(i=0;i<str.length;i++) 

if(str.charCodeAt(i) > 255) 
len++; 
len++; 

return len; 


function trimString(str) 

var i,j; 

if(str == "") return ""; 

for(i=0;i<str.length;i++) 
if(str.charAt(i) != ' ') break; 
if(i >= str.length) return ""; 

for(j=str.length-1;j>=0;j--) 
if(str.charAt(j) != ' ') break; 

return str.substring(i,j+1); 


function uisNum(str) 

var i, cChar; 

str = trimString(str); 

for(i=0;i<str.length;i++) 

cChar = str.charAt(i); 
if( !(("0"<=cChar) && (cChar<="9")) ) 
return false; 

return true; 


</script>


暂时没有评论
   发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:  我要注册 验证码: 
为防止广告注册机程序,验证码不会自动显示,请点击此处显示或者(刷新)验证码!
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字
确定发布?
最多可以输入200个字,目前你已经输入了0个字;你今日还可以发表10条评论!
 
   

CopyRight © 2008-2010 广东金融学院030904班 All Rights Reserved
Powered by www.030904.com