数据库如下:
id       name  parent(父节点) src(节点的链接地址) zt(该节点是否可以用,1为可用)
0 功能树 12      
1 采购管理 0      
11 采购订货 1 ../purchase/dpur.aspx 1 1 0
12 采购收货 1 ../purchase/spur.aspx 1 1 0
13 入库管理 1 ../purchase/rkgl.aspx 1 1 0
14 退库管理 1 ../purchase/tkgl.aspx 1 1 0
15 付款登记 1 ../purchase/fkdj.aspx 1 1 0
2 基本信息 0 1 0 1
21 公司基本信息 2 ../inf/company.aspx 1 0 1
22 供应商设置 2 ../inf/suppliers.aspx 1 0 1
23 货品档案设置 2 ../inf/goods.aspx 1 0 1
24 仓库设置 2 ../inf/stores.aspx 1 0 1
25 采购员设置 2 ../inf/purchasers.aspx 1 0 1
3 单据查询 0 1 1 0
31 订货单据 3 ../seek/dseek.aspx 1 1 0
32 收货单据 3 ../seek/sseek.aspx 1 1 0
33 入库单据 3 ../seek/rseek.aspx 1 1 0
34 退库单据 3 ../seek/tseek.aspx 1 1 0
35 付款单据 3 ../seek/fseek.aspx 1 1 0
36 综合查询 3 ../seek/zseek.aspx 1 1 0
4 基本信息查询 0 ../seek/inf.aspx 1 1 0
5 系统维护 0 1 0 0
41 操作权限设置 5 ../sysmanage/qxsz.aspx 1 0 0
42 数据备份 5 ../sysmanage/dmanage.aspx 1 0 0
43 数据清理 5 ../sysmanage/dmanage.aspx 1 0 0
44 数据还原 5 ../sysmanage/dmanage.aspx 1 0 0
6 退出系统 0 ../exit.aspx 1 1 1
以上是我的数据库设计,请问告示,如何根据zt这个数据列,来动态生成treeview呢??
麻烦给出详细的c#代码,在此先谢了!

解决方案 »

  1.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
    {
    CreateDataSet();
    InitTree(TreeView1.Nodes,"NONE");
    }
    } private DataSet CreateDataSet()
    {
    cmdSelect="select * from TreeTable";
    myCmd=new SqlDataAdapter(cmdSelect,this._conn.dbCon);
    ds=new DataSet();
    myCmd.Fill(ds,"tree");
    return ds;
    }
    private void InitTree(TreeNodeCollection Nds,string parentId)
    {
    DataView dv = new DataView();
    TreeNode tmpNd ;
    string intID;
    dv.Table = ds.Tables["tree"];
    dv.RowFilter = "parent= '"+parentId+"'";
    foreach(DataRowView drv in dv)
    {
    tmpNd = new TreeNode();
    tmpNd.ID = drv["StoreID"].ToString();
    tmpNd.Text = drv["StoreName"].ToString();
    tmpNd.CheckBox = true;
    Nds.Add(tmpNd);

    intID = drv["ParentStore"].ToString();
    InitTree(tmpNd.Nodes,tmpNd.ID);
    }
    }
      

  2.   

    其实如果是用c#做,就很简单,你如果真的是会c#的话,想想就可以了。
    但如果是用js做....那样就真是件难事了,难难难,但做出来的效果却是好好的。
    又如果是用js+xml做的话,就不难了...而且效果也好好,所以我建议呢,不要用数据库存结点记录,而用xml来存
      

  3.   

    这个是代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> DSTree </TITLE>
    <META NAME="Author" CONTENT="[email protected]" >
    <style>
    body,td{font:12px verdana}
    #treeBox{background-color:#fffffa;}
    #treeBox .ec{margin:0 5 0 5;}
    #treeBox .hasItems{font-weight:bold;height:20px;padding:3 6 0 6;margin:2px;cursor:hand;color:#555555;border:1px solid #fffffa;}
    #treeBox .Items{height:20px;padding:3 6 0 6;margin:1px;cursor:hand;color:#555555;border:1px solid #fffffa;}
    </style>
    <base href="http://vip.5d.cn/star/dstree/" />
    <script>
    //code by star 20003-4-7
    var HC = "color:#990000;border:1px solid #cccccc";
    var SC = "background-color:#efefef;border:1px solid #cccccc;color:#000000;";
    var IO = null;
    function initTree(){
    var rootn = document.all.menuXML.documentElement;
    var sd = 0;
    document.onselectstart = function(){return false;}
    document.all.treeBox.appendChild(createTree(rootn,sd));
    }
    function createTree(thisn,sd){
    var nodeObj = document.createElement("span");
    var upobj = document.createElement("span");
    with(upobj){
    style.marginLeft = sd*10;
    className = thisn.hasChildNodes()?"hasItems":"Items";
    innerHTML = "<img src=expand.gif class=ec>" + thisn.getAttribute("text") +"";

    onmousedown = function(){
    if(event.button != 1) return;
    if(this.getAttribute("cn")){
    this.setAttribute("open",!this.getAttribute("open"));
    this.cn.style.display = this.getAttribute("open")?"inline":"none";
    this.all.tags("img")[0].src = this.getAttribute("open")?"expand.gif":"contract.gif";
    }
    if(IO){
    IO.runtimeStyle.cssText = "";
    IO.setAttribute("selected",false);
    }
    IO = this;
    this.setAttribute("selected",true);
    this.runtimeStyle.cssText = SC;
    }
    onmouseover = function(){
    if(this.getAttribute("selected"))return;
    this.runtimeStyle.cssText = HC;
    }
    onmouseout = function(){
    if(this.getAttribute("selected"))return;
    this.runtimeStyle.cssText = "";
    }
    oncontextmenu = contextMenuHandle;
    onclick = clickHandle;
    } if(thisn.getAttribute("treeId") != null){
    upobj.setAttribute("treeId",thisn.getAttribute("treeId"));
    }
    if(thisn.getAttribute("href") != null){
    upobj.setAttribute("href",thisn.getAttribute("href"));
    }
    if(thisn.getAttribute("target") != null){
    upobj.setAttribute("target",thisn.getAttribute("target"));
    } nodeObj.appendChild(upobj);
    nodeObj.insertAdjacentHTML("beforeEnd","<br>") if(thisn.hasChildNodes()){
    var i;
    var nodes = thisn.childNodes;
    var cn = document.createElement("span");
    upobj.setAttribute("cn",cn);
    if(thisn.getAttribute("open") != null){
    upobj.setAttribute("open",(thisn.getAttribute("open")=="true"));
    upobj.getAttribute("cn").style.display = upobj.getAttribute("open")?"inline":"none";
    if( !upobj.getAttribute("open"))upobj.all.tags("img")[0].src ="contract.gif";
    }

    for(i=0;i<nodes.length;cn.appendChild(createTree(nodes[i++],sd+1)));
    nodeObj.appendChild(cn);
    }
    else{
    upobj.all.tags("img")[0].src ="endnode.gif";
    }
    return nodeObj;
    }
    window.onload = initTree;
    </script><script>
    function clickHandle(){
    // your code here 
    }
    function contextMenuHandle(){
    event.returnValue = false;
    var treeId = this.getAttribute("treeId");
    // your code here
    }
    </script>
    </HEAD>
    <BODY>
    <xml id=menuXML>
    <?xml version="1.0" encoding="GB2312"?>
    <DSTreeRoot text="根节点" open="true" href="http://" treeId="123">
    <DSTree text="技术论坛" open="false" treeId="">
    <DSTree text="5DMedia" open="false" href="http://" target="box" treeId="12">
    <DSTree text="网页编码" href="http://" target="box" treeId="4353" />
    <DSTree text="手绘" href="http://" target="box" treeId="543543" />
    <DSTree text="灌水" href="http://" target="box" treeId="543543" />
    </DSTree>
    <DSTree text="BlueIdea" open="false" href="http://" target="box" treeId="213">
    <DSTree text="DreamWeaver &amp; JS" href="http://" target="box" treeId="4353" />
    <DSTree text="FlashActionScript" href="http://" target="box" treeId="543543" />
    </DSTree>
    <DSTree text="CSDN" open="false" href="http://" target="box" treeId="432">
    <DSTree text="JS" href="http://" target="box" treeId="4353" />
    <DSTree text="XML" href="http://" target="box" treeId="543543" />
    </DSTree>
    </DSTree> <DSTree text="资源站点" open="false" treeId="">
    <DSTree text="素材屋" href="http://" target="box" treeId="12" />
    <DSTree text="桌面城市" open="false" href="http://" target="box" treeId="213">
    <DSTree text="壁纸" href="http://" target="box" treeId="4353" />
    <DSTree text="字体" href="http://" target="box" treeId="543543" />
    </DSTree>
    <DSTree text="MSDN" open="false" href="http://" target="box" treeId="432">
    <DSTree text="DHTML" href="http://" target="box" treeId="4353" />
    <DSTree text="HTC" href="http://" target="box" treeId="543543" />
    <DSTree text="XML" href="" target="box" treeId="2312" />
    </DSTree>
    </DSTree></DSTreeRoot>
    </xml>
    <table style="position:absolute;left:100;top:100;">
    <tr><td id=treeBox style="width:400px;height:200px;border:1px solid #cccccc;padding:5 3 3 5;" valign=top></td></tr>
    <tr><td style="font:10px verdana;color:#999999" align=right>by <font color=#660000>sTar</font><br> 2003-4-8</td></tr>
    </table>
    </BODY>
    </HTML>
      

  4.   

    那如果用xml做的话,应该如何呢?因为我的设计初衷是想通过一个页面来进行权限管理的,难道改一次权限管理就生成一个xml文件??
    可以举个例子吗??
      

  5.   

    改一次权限就修改一次XML不是生成一个新的