怎么样使树型结构程序支持字符型的ID。。。

diaorenhong 2003-08-20 09:55:37

怎样使下面的程序支持字符串的形式。。

应该怎么样修改下面的程序

id parentid context url
sa0000 sa0000 系统管理
sa0010 sa0000 系统出世华。。
sa0020 sa0000 ....
..............................
sb0000 sb0000 .......
sb0010 sb0000 ......

使得程序支持采用sa0000,sa0010字符串作为id ,parentid的值。。

源程序如下。。
怎么样修改才能使他支持字符串的形式。。

deeptree.asp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>CSDN deeptree---By Fason</title>
<link rel=stylesheet href="style.css" type="text/css">
</head>
<script>
function expand(id){
window.status=eval("s"+id).innerText;
getLight(id);


if(eval("s"+id).href!='')document.frames['nodehref'].location.href=eval("s"+id).

href
switch(eval("dir"+id).innerText){//改变"+","-"
case "-":


eval("dir"+id).innerText="+";eval("dir"+id).className='dirclose';document.getEle

mentById("load_"+id).style.display='none';break;
case "+":


eval("dir"+id).innerText="-";eval("dir"+id).className='diropen';document.getElem

entById("load_"+id).style.display='';break;
default:eval("dir"+id).innerText=".";eval("dir"+id).className='dirNode';
}
if(eval("dir"+id).innerText==".")return;


if(eval("dir"+id).innerText=="+"){if(document.getElementById("t"+id)){eval("t"+i

d).removeNode(true);return;}}
document.frames['hifm'].location.href="subtree.asp?id="+id
}

function getLight(id){//高亮度显示当前结点
var s=document.getElementsByTagName("SPAN")
var sn=document.getElementById("s"+id)


for(i=0;i<s.length;i++)if(s[i].className=='node')s[i].style.cssText="color:#0000

00;background-color:#f2f2f2"
sn.style.cssText="color:#000000;background-color:#ffffff;border:1 solid

#999999"
}
</script>
<body topmargin="0" leftmargin="0" scroll="no">
<% dim conn,rs
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &

Server.mappath("tree.mdb") & ";Persist Security Info=False"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "select *,(select count(*) from deeptree where parentid = id) as

children from deeptree where id=parentid",conn,1,3
%>
<div align="center">
<center>
<table border="0" width="779" cellspacing="0" cellpadding="0" height=100%

bgcolor="#F2F2F2">
<tr>
<td width="260" style="border-right:5 solid #6699cc" valign="top"

align="left">
<div id=treedir style="overflow:auto;width:100%;height:100%">
<table border='0' cellspacing='0' cellpadding='0'

style='position:relative;left:18;top:20' onselectstart="return false">
<%
do while not rs.eof
if rs("children")<=1 then
s="."
cls="dirNode"
else
s="+"
cls="dirclose"
end if
%>
<tr><td id='node<%=rs("id")%>' class='td_node' valign=top><span

class='<%=cls%>' id='dir<%=rs("id")%>'

onclick='expand(<%=rs("id")%>)'><%=s%></span><span class='node'

id='s<%=rs("id")%>' onclick='expand(<%=rs("id")%>)' title='<%=rs("content")%>'

href='<%=rs("link")%>'><%=rs("content")%></span></td></tr>
<% if rs("children")>1 then%>
<tr id="load_<%=rs("id")%>" style="display:none"><td

class='td_node'><table border='0' cellspacing='0' cellpadding='0'

style='position:relative;left:18;top:0'><tr><td class='td_node'><span

class='dirNode'>.</span><span

class='load'>Loading...</span></td></tr></table></td></tr>
<%end if%>
<% rs.movenext
loop
%>
</table>
</div>
</td>
<td valign="top" align="left">
<iframe name=nodehref style="border:1 solid

#3366cc;width:100%;height:100%;overflow:auto" src="about:blank" frameborder=0

></iframe>
</td>
</tr>
</table>
</center>
</div>
<%
set rs=nothing
set conn=nothing
%>
<iframe id='hifm' width=0 height=0></iframe>

</body>

subtree.asp

<% dim conn,rs,s,cls,href
dim nodeid
nodeid=request.querystring("id")
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &

Server.mappath("tree.mdb") & ";Persist Security Info=False"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "select *,(select count(*) from deeptree where parentid = T.id) as

children from deeptree T where parentid="&nodeid&" and

id<>"&CInt(nodeid),conn,1,3
dim node_html
node_html="<table id='t"&nodeid&"' border='0'

style='position:relative;left:18' cellspacing='0' cellpadding='0'>"
do while not rs.eof
if rs("id")<>rs("parentid") then
if rs("children")=0 then
s="."
cls="dirNode"
else
s="+"
cls="dirclose"
end if
end if
node_html=node_html&"<tr><td id='node"&rs("id")&"' class='td_node'><span

class='"&cls&"' id='dir"&rs("id")&"'

onclick='expand("&rs("id")&")'>"&s&"</span><span class='node' id='s"&rs("id")&"'

onclick='expand("&rs("id")&")' title='"&rs("content")&"'

href='"&rs("link")&"'>"&rs("content")&"</span></td></tr>"
if rs("children")>0 then
node_html=node_html&"<tr id='load_"&rs("id")&"' style='display:none'><td

class='td_node'><table border='0' cellspacing='0' cellpadding='0'

style='position:relative;left:18;top:0'><tr><td class='td_node'><span

class='dirNode'>.</span><span

class='load'>Loading...</span></td></tr></table></td></tr>"
end if
rs.movenext
loop
node_html=node_html&"</table>"
set rs=nothing
set rs = Server.CreateObject("ADODB.Recordset")
rs.open "select link from deeptree where id="&nodeid,conn,1,3
%>
<script>
if(parent.document.getElementById("load_"+"<%=nodeid%>")){
parent.document.getElementById("load_"+"<%=nodeid%>").style.display="none"
parent.document.getElementById("node"+<%=nodeid%>).innerHTML+="<%=node_html%>"
}
</script>
<% set rs=nothing
set conn=nothing
%>




...全文
58 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2003-09-13
  • 打赏
  • 举报
回复
仿照csdn左面的菜单的ASP+数据库无限级树菜单代码分享

近来问无限级数据库树菜单人很多,我就自己做了一个仿照csdn左面的菜单,自己暂时不用,完全是给大家分享的,要数据库和代码文件请到www.ymdg.com/tree.rar下载,如果有人提供空间存放那是最好了。
本文完全采用大家熟悉的ASP(VBS)制作,过写日子我再写一个基于XML技术的给大家。
QQ:28963147,email:panyuguang962@sohu.com
感谢CSDN和全体网友!
说明:
Access数据库
● 数据库名:tree
● 表名:tree
● 字段名的设计
ID 文本类型 编码
Name 文本类型 节点文字
HyperLink 文本类型 相关信息
---------------------------------------------------
ID | Name | HyperLink
---------------------------------------------------
1_1_1 | ASP | http://www.csdn.net
---------------------------------------------------
1_1_1_1 | DHTML | http://www.csdn.net
---------------------------------------------------
1_2_2 | JAVA | http://www.csdn.net
---------------------------------------------------
1_1_2 | JavaScript | http://www.csdn.net
---------------------------------------------------
1_2_1 | VB | http://www.csdn.net
---------------------------------------------------
1_2_1_2 | VBA | http://www.csdn.net
---------------------------------------------------
1_1 | WEB开发 | http://www.csdn.net
---------------------------------------------------
1 | WWW.CSDN.net | http://www.csdn.net
---------------------------------------------------
1_2_1_1 | 基础类 | http://www.csdn.net
---------------------------------------------------
1_3_1 | 基础类 | http://www.csdn.net
---------------------------------------------------
1_2 | 开发语言 | http://www.csdn.net
---------------------------------------------------
1_1_1_2 | 内建对象 | http://www.csdn.net
---------------------------------------------------
1_3 | 数据库 | http://www.csdn.net
----------------------------------------------------
文件:nolimited.asp经简单测试好用!代码如下:
<html>
<head>
<META name=VI60_defaultClientScript content=VBScript>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>asp树的研究</title>
</head>
<style type="text/css">
<!--
.aa {
font-size: 14px;
color: #000000;
text-align: center;
vertical-align: middle;
letter-spacing: 0px;
word-spacing: 0px;
}
-->
</style>
<body bgcolor="DEE3F7">
<%
dim cn,rs,SQL ,Para,NumChild
set cn=server.CreateObject("ADODB.connection")
set rs=server.createobject("ADODB.recordset")
set rs1=server.createobject("ADODB.recordset")
cn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("tree.mdb")
SQL="Select * from tree order by ID"
rs.open SQL,cn,3,2
do while not rs.EOF
SQL="Select ID from tree where ID like '" & rs("ID") & "%' and ID<>'" & rs("ID") & "' order by ID"
Para=rs("ID") & "|"
NumChild=0
rs1.open SQL,cn, 3,2
NumChild=rs1.RecordCount
do while not rs1.EOF
Para =Para & rs1("ID") & "|"
rs1.MoveNext
loop
Para=cstr(trim(left(Para,len(Para)-1)))
rs1.Close
%>
<table id="T<%=rs("ID")%>"
border=1
cellpadding=0
cellspacing=0
bordercolor="#DEE3F7"
class="aa"
abbr="<%=Para%>"
summary=<%=checkid(rs("ID"))%>
style="cursor:hand"
onClick="vbs:subtree '<%=Para%>'" >

<tr>
<td width="<%=17+checkid(rs("ID"))*20%>"
height="20" align="right">
<table width="20" height="20" border="1" cellpadding="0" cellspacing="0" bordercolor="#DEE3F7">
<tr>

<td align="center" valign="middle" bordercolor="#000000" id="R<%=rs("ID")%>" ><%if NumChild=0 then Response.Write "." else Response.Write "-"%></td>
</tr>
</table>
</td>

<td height="20"
nowrap
bordercolor="#FFFFFF"
onMouseOver="vbs:me.bgcolor='#CCCCCC':me.bordercolor='#999999'"
onMouseOut="vbs:me.bgcolor='#DEE3F7':me.bordercolor='#ffffff'"
title="<%=rs("HyperLink")%>">
<%=rs("Name")%></td>
</tr>
</table>


<%
rs.MoveNext
loop
rs.Close:set rs=nothing
cn.Close:set cn=nothing
function checkid(x)
dim Tempnum
Tempnum=0
for i=1 to len(x)
if mid(x,i,1)="_" then
Tempnum=Tempnum+1
end if
next
checkid=Tempnum
end function


%>
<script language=VBS>
sub subtree(Client_para)
if instr(Client_para,"|")=0 then exit sub
Myarray=split(Client_para,"|")
Mytext=eval("R" & Myarray(0) & ".innertext")
select case Mytext
case "+"
document.all.item("R" & Myarray(0)).innertext="-"
for i=1 to ubound(Myarray)
if eval("T" & Myarray(i) & ".summary")-eval("T" & Myarray(0) & ".summary")=1 then
document.all.item("T" & Myarray(i)).style.display="block"
end if
if eval("T" & Myarray(i) & ".summary")-eval("T" & Myarray(0) & ".summary")>1 then
document.all.item("T" & Myarray(i)).style.display="none"
end if
next
case "-"
document.all.item("R" & Myarray(0)).innertext="+"
for i=1 to ubound(Myarray)
if eval("T" & Myarray(i) & ".summary")-eval("T" & Myarray(0) & ".summary")>=1 then
document.all.item("T" & Myarray(i)).style.display="none"
if eval("R" & Myarray(i) & ".innertext")="-" then
document.all.item("R" & Myarray(i)).innertext="+"
end if
end if
next
end select
set Myarray=nothing
end sub

Sub document_onselectstart
document.selection.clear
End Sub

if isobject(eval("T1")) then
subtree document.all("T1").abbr
subtree document.all("T1").abbr
end if
</script>

</html>




diaorenhong 2003-08-20
  • 打赏
  • 举报
回复
数据库结构
id parentid content link

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧