Board logo

标题: [ASP] 整理了一些ASP初学者常用的代码(下) [打印本页]

作者: rensheng5    时间: 2006-6-3 11:48     标题: 整理了一些ASP初学者常用的代码(下)

':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: test harness :::
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 

' to test, we'll just try to show all files with a .gif extension in the root of c:
set objfso = createobject("scripting.filesystemobject")
set objf = objfso.getfolder("c:\")
set objfc = objf.files
response.write "<table border=""0"" cellpadding=""5"">"
for each f1 in objfc
if instr(ucase(f1.name), ".gif") then
response.write "<tr><td>" & f1.name & "</td><td>" & f1.datecreated & "</td><td>" & f1.size & "</td><td>"
if gfxspex(f1.path, w, h, c, strtype) = true then
response.write w & " x " & h & " " & c & " colors"
else
response.write " "
end if
response.write "</td></tr>"
end if
next
response.write "</table>"
set objfc = nothing
set objf = nothing
set objfso = nothing 

%>
24.点击返回上页代码:
<form>
<p><input type="button" value="返回上一步" onclick="history.back(-1)"></p>
</form>
24.点击刷新代码:
<form>
<p><input type="button" value="刷新按钮一" onclick="reloadbutton()"></p>
</form>
<script language="javascript"><!--
function reloadbutton(){location.href="allbutton.htm";}
// --></script> 

24.点击刷新代码2:
<form>
<p><input type="button" value="刷新按钮二" onclick="history.go(0)"> </p>
</form> 

<form>
<p><input type="button" value="打开一个网站" onclick="homebutton()"></p>
</form>
<script language="javascript"><!--
function homebutton(){location.href="http://nettrain.126.com";;;}
// --></script> 

25.弹出警告框代码:
<form>
<p><input type="button" value="弹出警告框" onclick="alertbutton()"></p>
</form>
<script language="javascript"><!--
function alertbutton(){window.alert("要多多光临呀!");}
// --></script> 

26.状态栏信息
<form>
<p><input type="button" value="状态栏信息" onclick="statusbutton()"></p>
</form>
<script language="javascript"><!--
function statusbutton(){window.status="要多多光临呀!";}
// --></script> 

27.背景色变换
<form>
<p><input type="button" value="背景色变换" onclick="bgbutton()"></p>
</form>
<script>function bgbutton(){
if (document.bgcolor=='#00ffff')
{document.bgcolor='#ffffff';}
else{document.bgcolor='#00ffff';}
}
</script> 

28.点击打开新窗口
<form>
<p><input type="button" value="打开新窗口" onclick="newwindow()"></p>
</form>
<script language="javascript"><!--
function newwindow(){window.open("http://www.mcmx.com";;,"","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}
// --></script></body>
29.分页代码:
<%''本程序文件名为:pages.asp%>
<%''包含ado常量表文件adovbs.inc,可从"\program files\common files\system\ado"目录下拷贝%>
<!--#include file="adovbs.inc"-->
<%''*建立数据库连接,这里是oracle8.05数据库
set conn=server.createobject("adodb.connection")
conn.open "provider=msdaora.1;data source=yoursrcname;user id=youruserid;password=yourpassword;"  

set rs=server.createobject("adodb.recordset") ''创建recordset对象
rs.cursorlocation=aduseclient ''设定记录集指针属性
''*设定一页内的记录总数,可根据需要进行调整
rs.pagesize=10  

''*设置查询语句
strsql="select id,姓名,住址,电话 from 通讯录 order by id"
rs.open strsql,conn,adopenstatic,adlockreadonly,adcmdtext
%>
<html>
<head>
<title>分页示例</title>
<script language=javascript>
//点击"[第一页]"时响应:
function pagefirst()
{
document.myform.currentpage.selectedindex=0;
document.myform.currentpage.onchange();
}
//点击"[上一页]"时响应:
function pageprior()
{
document.myform.currentpage.selectedindex--;
document.myform.currentpage.onchange();
}
//点击"[下一页]"时响应:
function pagenext()
{
document.myform.currentpage.selectedindex++;
document.myform.currentpage.onchange();
}
//点击"[最后一页]"时响应:
function pagelast()
{
document.myform.currentpage.selectedindex=document.myform.currentpage.length-1;
document.myform.currentpage.onchange();
}
//选择"第?页"时响应:
function pagecurrent()
{ //pages.asp是本程序的文件名
document.myform.action='pages.asp?page='+(document.myform.currentpage.selectedindex+1)
document.myform.submit();
}
</script>
</head>
<body bgcolor="#ffffcc" link="#008000" vlink="#008000" alink="#ff0000""> 

<%if rs.eof then
response.write("<font size=2 color=#000080>[数据库中没有记录!]</font>")
else
''指定当前页码
if request("currentpage")="" then
rs.absolutepage=1
else
rs.absolutepage=clng(request("currentpage"))
end if  

''创建表单myform,方法为get
response.write("<form method=get name=myform>")
response.write("<p align=center><font size=2 color=#008000>")
''设置翻页超链接
if rs.pagecount=1 then
response.write("[第一页] [上一页] [下一页] [最后一页] ")
else
if rs.absolutepage=1 then
response.write("[第一页] [上一页] ")
response.write("[<a href=java script:pagenext()>下一页</a>] ")
response.write("[<a href=java script:pagelast()>最后一页</a>] ")
else
if rs.absolutepage=rs.pagecount then
response.write("[<a href=java script:pagefirst()>第一页</a>] ")
response.write("[<a href=java script:pageprior()>上一页</a>] ")
response.write("[下一页] [最后一页] ")
else
response.write("[<a href=java script:pagefirst()>第一页</a>] ")
response.write("[<a href=java script:pageprior()>上一页</a>] ")
response.write("[<a href=java script:pagenext()>下一页</a>] ")
response.write("[<a href=java script:pagelast()>最后一页</a>] ")
end if
end if
end if 

''创建下拉列表框,用于选择浏览页码
response.write("第<select size=1 name=currentpage onchange=pagecurrent()>")
for i=1 to rs.pagecount
if rs.absolutepage=i then
response.write("<option selected>"&i&"</option>") ''当前页码
else
response.write("<option>"&i&"</option>")
end if
next
response.write("</select>页/共"&rs.pagecount&"页 共"&rs.recordcount&"条记录</font><p>")
response.write("</form>") 

''创建表格,用于显示
response.write("<table align=center cellspacing=1 cellpadding=1 border=1")
response.write(" bordercolor=#99ccff bordercolordark=#b0e0e6 bordercolorlight=#000066>") 

response.write("<tr bgcolor=#ccccff bordercolor=#000066>")  

set columns=rs.fields  

''显示表头
for i=0 to columns.count-1
response.write("<td align=center width=200 height=13>")
response.write("<font size=2><b>"&columns(i).name&"</b></font></td>")
next
response.write("</tr>")
''显示内容
for i=1 to rs.pagesize
response.write("<tr bgcolor=#99ccff bordercolor=#000066>")
for j=0 to columns.count-1
response.write("<td><font size=2>"&columns(j)&"</font></td>")
next
response.write("</tr>") 

rs.movenext
if rs.eof then exit for
next 

response.write("</table>")  

end if
%>
</body>
</html>
作者: kalidoit    时间: 2006-11-13 10:27

好.
作者: feng1566    时间: 2006-12-3 12:51

谢谢!!!!
作者: qianglc    时间: 2007-2-11 22:20

非常感谢呀
作者: mable2294    时间: 2007-3-23 08:31

好.绝对支持!!!!!!
作者: smke16    时间: 2007-5-4 20:43

非常感谢 嘿嘿




欢迎光临 逐梦论坛 (http://temp2023.zhumeng.org/) Powered by Discuz! 7.2