热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用DW用ASP+ACCESS编写目录树

利用ACCESS创建数据库listBase.mdb:数据表:listTable数据字段:listIdlistNamelistInfoparentId连接方法:%dimsConn,sConnStr,sSqlsConnStrDRIVER{MicrosoftAccessDriver(*.mdb)};dbqserver.mappath(listBase.mdb)setsConnserver.createobjec

利用ACCESS创建数据库listBase.mdb: 数据表:listTable 数据字段:listIdlistNamelistInfoparentId 连接方法: % dimsConn,sConnStr,sSql sCOnnStr="DRIVER={MicrosoftAccessDriver(*.mdb)};dbq="server.mappath("listBase.mdb") setsCOnn=server.createobjec

利用ACCESS创建数据库listBase.mdb:

数据表:listTable

数据字段:listIdlistNamelistInfoparentId 连接方法:

<%

dimsConn,sConnStr,sSql

sCOnnStr="DRIVER={MicrosoftAccessDriver(*.mdb)};dbq="&server.mappath("listBase.mdb")

setsCOnn=server.createobject("adodb.connection")

sConn.opensConnStr

%>

把以上代码保存成文件:initialize.asp 下面这段程序代码是用来显示目录树用的,保存成文件:inc.asp







<%

response.write("" & chr(13))

response.write("" & chr(13)&"" & chr(13))

response.write("" & chr(13) & "" & chr(13) & "" & chr(13) & "
" & chr(13) & "")

response.write("" & chr(13) & "" & chr(13))

response.write("

response.write("
 
" & chr(13))

'下面代码为显示目录树最关键的函数,使用了递归方法(很多象这样类型的都是用递归来做的。)

function listChild(id)

dim sRec,sSql,sNum,sTmp

set sRec=server.createobject("adodb.recordset")

sSql="select listId,listName,listInfo,parentId from listTable where parentId=" & id

sRec.open sSql,sConn,3,1

if not sRec.eof then

sNum=1

response.write("" & chr(13))

while not sRec.eof

sTmp=sConn.execute("select count(listId) as countSub from listTable where parentId=" & sRec("listId"))

if sTmp("countSub")>0 then

response.write("" & chr(13))

if sNum=sRec.recordcount then

response.write("" & chr(13))

else

response.write("" & chr(13))

end if

response.write("
" & chr(13) & "" & chr(13))

response.write("" & chr(13) & "
if sNum=sRec.recordcount then

response.write("" & chr(13))

else

response.write("" & chr(13))

end if

response.write("" & chr(13) & "" & chr(13))

else

response.write("" & chr(13))

if sNum=sRec.recordcount then

response.write("" & chr(13))

else

response.write("" & chr(13))

end if

response.write("
" & chr(13) & "" & chr(13))

response.write("" & chr(13) & "" & chr(13) & "
" & chr(13))

end if

sRec.close '关闭记录集

set sRec=nothing '关闭记录集

end function

sConn.close '关闭数据库链接

set sCOnn=nothing '关闭数据库链接

%>

下面这是调用页代码,保存成index.asp

<%@LANGUAGE='Vbscript' CODEPAGE='936'%>

















































点击关闭



















































 

 

 
 






























下面是提交信息处理页的代码,保存为disp.asp



<%

function checkstr(str)

str=replace(str,"'","''",1,-1,1)

checkstr=str

end function

dim disp,parentId,listName,listInfo

disp=request.QueryString("disp")

parentId=request.QueryString("parentId")

select case disp

case "add"

listName=checkstr(left(request.QueryString("listName"),10))

listInfo=checkstr(left(request.QueryString("listInfo"),50))

if listName="" then listName="空白节点"

if listInfo="" then ListInfo="此节点在添加入未填写内容"

sSql="insert into listTable (listName,listInfo,parentId) values('" & listName & "','" & listInfo & "'," & parentId & ")"

case "edit"

listName=checkstr(left(request.QueryString("listName"),10))

listInfo=checkstr(left(request.QueryString("listInfo"),50))

if listName="" then listName="空白节点"

if listInfo="" then listInfo="此节点在添加入未填写内容"

sSql="update listTable set listName='" & listName & "',listInfo='" & listInfo & "' where listId=" & parentId

case "del"

sSql="delete from listTable where listId=" & parentId & " or parentId=" & parentId

end select

sConn.execute sSql,,1

response.redirect("index.asp")

%> 以上代码保存成的文件放在同一目录下面(在这里我们称为根目录)。

在根目录下新建一个CSS目录.

下面为CSS定义,保存成css.css文件,放在CSS目录下。注:有一两个样式是不要的,我没删

.menuPro{

border-top:1pxdotted#A5BBE0;

border-right:1pxdotted#31548E;

border-bottom:1pxdotted#31548E;

border-left:1pxdotted#A5BBE0;

overflow:visible;

font-family:"Verdana","Arial","Helvetica","sans-serif";

font-size:12px; }

.menuGro{

border-top:2pxoutset#31548E;

border-right:2pxoutset#A5BBE0;

border-bottom:2pxoutset#A5BBE0;

border-left:2pxoutset#31548E;

overflow:visible;

font-family:"Verdana","Arial","Helvetica","sans-serif";

font-size:12px;

}

.menuFont{

font-family:"Verdana","Arial","Helvetica","sans-serif";

font-size:12px;

}

.showDiv{

display:'';

}

.hiddenDiv{

display:none;

}

.treeDiv{

background-color:#A8D5EA;

height:100%;

width:100%;

border-top-width:2px;

border-right-width:2px;

border-bottom-width:2px;

border-left-width:2px;

border-top-style:inset;

border-right-style:inset;

border-bottom-style:inset;

border-left-style:inset;

border-top-color:#3680C9;

border-right-color:#BCD5ED;

border-bottom-color:#BCD5ED;

border-left-color:#3680C9;

overflow:auto;

padding:20px;

}

body{

overflow:hidden;

}

.formDiv{

font-family:"Verdana","Arial","Helvetica","sans-serif";

font-size:12px;

font-weight:normal;

background-color:#7ABDDE;

height:200px;

width:300px;

border-top:1pxoutset#B9DCFF;

border-right:1pxoutset#004488;

border-bottom:1pxoutset#004488;

border-left:1pxoutset#B9DCFF;

overflow:hidden;

}

.text1{

width:160px;

}

.DivBut{

font-family:"Verdana","Arial","Helvetica","sans-serif";

font-size:12px;

font-weight:normal;

background-color:#3399CC;

height:20px;

width:40px;

border:1pxoutset; }

另在根目录下建一个IMAGES目录。用来放那些文件夹样子的小图。 打包下载[请使用WINRAR3.0解压]:小图片
推荐阅读
author-avatar
北京草舞945share
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有