<%
Dim str_UserId '用户ID
Dim str_Sql 'SQL语句
Dim str_ErrKind '错误类型
Dim obj_AimID '目标ID字典
Dim obj_AimUpID '上级目标ID字典
Dim obj_AimTitle '目标概要字典
Dim str_AimID '目标ID临时变量
Dim str_AimUpID '上级目标ID临时变量
Dim str_AimTitle '目标概要临时变量
str_UserId = Request.Cookies("user_id") '用户ID
Set obj_AimID = Server.CreateObject("Scripting.Dictionary")
Set obj_AimUpID = Server.CreateObject("Scripting.Dictionary")
Set obj_AimTitle = Server.CreateObject("Scripting.Dictionary")
If Trim(str_UserId) = "" Then
Response.End
End If
str_Sql = " Select aim_id,aim_up_id,aim_title From " & sTBL_US_AIM & " Where user_id='" & str_UserId & "' order by aim_id"
If Not obj_AimID.Exists(str_AimID) Then
obj_AimID.Add str_AimID,str_AimID
obj_AimUpID.Add str_AimID,str_AimUpID
obj_AimTitle.Add str_AimID,str_AimTitle
End If
s_flg = 0
For Each objItem In obj_AimID
If obj_AimUpID(objItem) = i_str_aim_id And obj_AimID(objItem) <> i_str_aim_id Then
s_flg = 1
End If
Next
If s_flg = 1 Then
Response.write Chr(13) & "<UL>"
For Each objItem In obj_AimID
If obj_AimUpID(objItem) = i_str_aim_id And obj_AimID(objItem) <> i_str_aim_id Then
Response.write Chr(13) & "<LI>"
Response.write "<a href='aim_show?aim_id=" & objItem & "'>-"
Response.write obj_AimTitle.Item(objItem) & "</a></LI>"
Call SetSubAim(objItem)
End If
Next
Response.write "</UL>"
End If
End Sub
%>
<html>
<head>
<style TYPE="text/css">
/* Outline Style Sheet */
UL UL {display: none; margin-left: 20pt}
</style>
<script LANGUAGE="JavaScript">
<!--
function checkParent(src, dest) {
// Search for a specific parent of the current element
while (src!=null)
{
if (src.tagName == dest) return src;
src = src.parentElement;
}
return null;
}
function outline() {
// Expand or collapse if a list item is clicked.
var open = event.srcElement;
// Make sure clicked inside an LI. This test allows rich HTML inside lists.
var el = checkParent(open, "LI");
if (null!=el) {
var pos = 0;
// Search for a nested list
for (var pos=0; pos<el.children.length; pos++) {
if ("UL"==el.children[pos].tagName) break;
}
if (pos==el.children.length) return;
} else return;
el = el.children[pos];
if ("UL"==el.tagName) {
// Expand or Collapse nested list
if (""==el.style.display) {
el.style.display = "block";
el.style.listStyleImage = "url(images/folder.gif)";
el.parentElement.style.listStyleImage = "url(images/ofolder.gif)";
}
else {
el.style.display = "";
el.parentElement.style.listStyleImage = "url(images/folder.gif)";
}
}
event.cancelBubble = true;
}
document.onclick = outline;
-->
</script>
下面的例子经过本人调试成功,如果你也调试成功请快结贴,我好升级到3个▲(可怜啊!看看别人都带上星了)。 数据库的表结构是cur_id,par_id,f_name.其中:所有的根结点的par_id为-1;而且所有的字段均为VARCHAR2类型。
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not IsPostBack Then
intiTree(TreeView2.Nodes, "-1")
End If
End Sub
Private Sub intiTree(ByRef Nds As TreeNodeCollection, ByVal parentId As String)
Dim sql As String = "select * from xj.treeview where par_id='" + parentId + "'"
Dim myDataAdapter As New OleDbDataAdapter(sql, con)
Dim ds As New DataSet()
myDataAdapter.Fill(ds, "tree")
Dim mydatable As DataTable
mydatable = ds.Tables("tree")
If mydatable.Rows.Count = 0 Then
Exit Sub
End If
Dim drv As DataRowView
Dim tmpNd As TreeNode
For Each drv In mydatable.DefaultView
tmpNd = New TreeNode()
Dim strid As String
strid = drv("CUR_ID")
tmpNd.ID = strid
tmpNd.Text = drv("F_NAME")
Nds.Add(tmpNd)
intiTree(tmpNd.Nodes, strid)
Next
End Sub
你的表结构基本上是正确的,不过再加几个字段看看!
T_TreeInfo表名
Item_id 主键
Item_pid 父目录id
Item_name目录名
Item_child子目录数
Item_layer层次数
Item_order顺序
link_page 链接页面
sqlString="SELECT * FROM T_TreeInfo ORDER BY Item_order"
然后生成dt
for each dr in dt.rows
在这里面要判断:
layer用来在前面加一个空格,以形成缩近结构,用for循环实现;
child用来判断没有子目录,用那么展开合扰图片,否则用其它图片
用session("")保存目录的展开合扰状态,合扰时子目录不会显示;