读取数据库动态创建目录树[WEB学习示例]

我的程序 | 2009-11-24 19:23:22 | 阅读 1003 次 | 评论(1)

if (!Page.IsPostBack)
        {
            //TreeView1.Nodes.Clear();
            TreeNode nNode = new TreeNode("在职");
            TreeNode pNode = new TreeNode("离职");
            TreeView1.Nodes.Add(nNode);
            TreeView1.Nodes.Add(pNode);
        }

    }
    protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        if (e.Node.ChildNodes.Count == 0)
        {
            if (e.Node.Depth == 0)
            { tiancong_geng(e.Node); }
            else if (e.Node.Depth == 1)
            { tiancong_ye(e.Node); }
            /*else if (e.Node.Depth == 2)
            { tiancong_ye1(e.Node); }
            else if (e.Node.Depth == 3)
            { tiancong_ye2(e.Node); }*/
        }
    }

    void tiancong_geng(TreeNode Node)
    {

        Socut.Reader MinCheng = new Socut.Reader("SELECT * FROM GJ_ZIYUAN order by GJ_ID asc");
        while (MinCheng.Read())
        {
            bool KG = false;
            TreeNode geng = new TreeNode(MinCheng["GJ_QUYU"].ToString());
            geng.PopulateOnDemand = true;
            geng.SelectAction = TreeNodeSelectAction.Expand;
            int a = Node.ChildNodes.Count;
            if (a > 0)
            {
                for (int jie = 0; jie < a; jie++)
                {
                    if (Node.ChildNodes[jie].Text == MinCheng["GJ_QUYU"].ToString())
                    { KG = true; break; }
                }
                if (KG == false) { Node.ChildNodes.Add(geng); }
            }
            else { Node.ChildNodes.Add(geng); }

        }
        MinCheng.Close();

    }

    void tiancong_ye(TreeNode Node)
    {
        Socut.Reader MinCheng = new Socut.Reader("SELECT * FROM GJ_ZIYUAN order by GJ_ID asc");
        while (MinCheng.Read())
        {
            TreeNode geng = new TreeNode(MinCheng["GJ_JIFAN"].ToString(), "", MinCheng["GJ_JIFAN"].ToString());
            geng.PopulateOnDemand = true;//false
            geng.SelectAction = TreeNodeSelectAction.None;

            if (Node.Text == MinCheng["GJ_QUYU"].ToString())
            { Node.ChildNodes.Add(geng); }

        }
        MinCheng.Close();
    }

    void tiancong_ye1(TreeNode Node)
    {
        Socut.Reader MinCheng = new Socut.Reader("SELECT * FROM GJ_ZIYUAN");
        while (MinCheng.Read())
        {
            TreeNode geng = new TreeNode(MinCheng["GJ_JIFAN"].ToString(), MinCheng["GJ_JIFAN"].ToString());
            geng.PopulateOnDemand = false;//true
            geng.SelectAction = TreeNodeSelectAction.None;
            Node.ChildNodes.Add(geng);
        }
        MinCheng.Close();

    }

    void tiancong_ye2(TreeNode Node)
    {
        Socut.Reader MinCheng = new Socut.Reader("SELECT * FROM Fo_Xian");
        while (MinCheng.Read())
        {
            TreeNode geng = new TreeNode(MinCheng["Ming_Cheng"].ToString(), MinCheng["ChuanJian_Ren"].ToString());
            geng.PopulateOnDemand = false;
            geng.SelectAction = TreeNodeSelectAction.None;
            Node.ChildNodes.Add(geng);
        }
        MinCheng.Close();

    }

文章评论,共1条
大活宝
2009-11-25 13:33
1
<a href="http://www.open-open.com/ajax/ajax20090603084814.htm" target="_blank">http://www.open-open.com/ajax/ajax20090603084814.htm</a> 研究下这个吧
游客请输入验证码