利用Access创建数据库listBase.mdb:
数据表:listTable
数据字段:listIdlistNamelistInfoparentId
连接方法:
<%
dim sConn,sConnStr,sSql
sConnStr="DRIVER={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("listBase.mdb")
set sConn=server.createobject("adodb.connection")
sConn.open sConnStr
%>
把以上代码保存成文件:initialize.asp
下面这段程序代码是用来显示目录树用的,保存成文件:inc.asp
<%
response.write("
cellspacing='0' cellpadding='0'>" & chr(13))
response.write("
" & chr(13)&"" & chr(13) & " ")response.write(" " & chr(13) & "style=cursor:hand alt=不可修改 />
| " & chr(13) & " " & chr(13)) response.write(" " & chr(13))response.write(" " & chr(13))response.write(" | |
" & chr(13))
response.write("
" & chr(13) & "
" & 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("
cellspacing='0' cellpadding='0'>" & 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("
background='images/eline.gif' valign='top'>
| " & chr(13))end if
response.write("
" & chr(13) & "cellspacing='0' cellpadding='0'>" & chr(13)) response.write(" " & chr(13) & " " & chr(13) & " class='menuFont'> style='cursor:hand' onclick="" jscript:showForm('add'," & sRec("listId") & ")""> 添加 | " & chr(13))response.write(" " & chr(13) & " | " & chr(13) & " " & chr(13) & " " & chr(13) & " | " & chr(13) & "
" & chr(13))response.write("
" & 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) & "width='100%' border='0' cellspacing='0' cellpadding='0'>" & chr(13)) response.write(" " & chr(13) & "class='menuPro' id='listName" & sRec("listId") & "'> " & server.HTMLEncode(sRec("listName")) & " | " & chr(13) & "" & chr(13))response.write(" " & chr(13) & " | " & chr(13) & " " & chr(13) & " " & chr(13) & " | " & chr(13) & "
" & chr(13))end if
sRec.movenext
sNum=sNum+1
wend
response.write("
" & chr(13))
end if
sRec.close '关闭记录集
set sRec=nothing '关闭记录集
end function
sConn.close '关闭数据库链接
set sConn=nothing '关闭数据库链接
%>