javascript写的tree,支持无限级分类。 dtree.zip
Code
<div id="tree">
<script>
d = new dTree('d');
d.add('0','-1','TREE');
</script>
<%
SqlCommand cmd = new SqlCommand("select * from category", getConnection());
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
%>
<script>
d.add('<%=dr["id"] %>','<%=dr["parentid"] %>','<%=dr["category"] %>','Default.aspx?id=<%=dr["id"] %>');
</script>
<%
}
%>
<script>
document.write(d);
</script>
<%
%>
</div>
<div id="tree">
<script>
d = new dTree('d');
d.add('0','-1','TREE');
</script>
<%
SqlCommand cmd = new SqlCommand("select * from category", getConnection());
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
%>
<script>
d.add('<%=dr["id"] %>','<%=dr["parentid"] %>','<%=dr["category"] %>','Default.aspx?id=<%=dr["id"] %>');
</script>
<%
}
%>
<script>
document.write(d);
</script>
<%
%>
</div>
数据表:
id int identity,
category varchar(100), --类别名称
parentid int --父id