表中有字段
id name Tid
1 层1 1
2 层1 1
3 层1 1
4 层2 1
5 层2 2
Tid 对应本表,为父ID
就是这样的一个循环,下面具体有多少层这个数量不定
用TreeView来显示,怎么显示呀,用
foreach (Test t in iList)
{
}
这种方法好像不管用,代码怎么写,救救呀,明天要交货了
------解决方案--------------------------------------------------------
我只看看我不说话
------解决方案--------------------------------------------------------
我以前是这么做的
提供一个Demo 你自己替换一下
- C# code
/// <summary> /// 给当前节点添加子节点 /// </summary> /// <param name="node">当前节点</param> /// <param name="pid">当前节点的ID</param> protected void AddPages(TreeNode node, string pid) { DataSet ds = lm.GetPage(pid); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { TreeNode childnode = new TreeNode(); childnode.Text = dr["BigPageName"].ToString(); childnode.NavigateUrl = "bbsSolution.aspx?PageId=" + dr["PageId"].ToString(); childnode.Target = "mainFrame"; //给当前节点添加子节点 AddPages(childnode, dr["PageId"].ToString()); if (node == null) { TreeView1.Nodes.Add(childnode); } else { node.ChildNodes.Add(childnode); } } } }
------解决方案--------------------------------------------------------
HTML
- HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Left.aspx.cs" Inherits="Left" %><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title> <script language="javascript"> function chkAll() { //debugger; var chkall= document.all["chkall"]; var chkother= document.getElementsByTagName("input"); for (var i=0;i<chkother.length;i++) { if( chkother[i].type=='checkbox') { if(chkother[i].id.indexOf('TreeView1')>-1) { if(chkall.checked==true) { chkother[i].checked=true; } else { chkother[i].checked=false; } } } } } </script></head><body> <form id="form1" runat="server"> <table width=100% height=100%> <tr height=10> <td><input id="chkall" type="checkbox" onclick="chkAll();" />全选/取消</td> <td><asp:Button ID="Button1" runat="server" Text="Button" /></td> </tr> <tr valign=top> <td><asp:TreeView ID="TreeView1" runat="server" ></asp:TreeView></td> <td><iframe id=fMain style="BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none" src="" frameBorder="0" width="100%" scrolling="yes" height="100%"></iframe></td> </tr> <tr height=10> <td></td> </tr> </table> </form></body></html>