zoukankan      html  css  js  c++  java
  • ASP.NET树形

    /// <summary>
        /// 树行绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void treeviewProductDataBind()
        {
            //根节点
            DataTable dtCategories = objDs.GetData();
            int categoriesLen = dtCategories.Rows.Count;
            //子节点
            DataTable dtProductsCount = objDs.GetDataBy();
            int productsLen = dtProductsCount.Rows.Count;
            //添加根节点
            for (int i = 0; i < categoriesLen; i++)
            {
                TreeNode treenodeParent = new TreeNode();
                treenodeParent.Text = dtCategories.Rows["departmentname"].ToString();
                treenodeParent.Value = dtCategories.Rows["departmentid"].ToString();
                treenodeParent.NavigateUrl = "Departmen.aspx?departmentid=" + treenodeParent.Value.ToString();
                this.TreeView1.Nodes.Add(treenodeParent);
                //添加子节点
                for (int j = 0; j < productsLen; j++)
                {
                    if (dtCategories.Rows["departmentid"].ToString() == dtProductsCount.Rows[j]["parentid"].ToString())
                    {
                        TreeNode treenodeChild = new TreeNode();
                        treenodeChild.Text = dtProductsCount.Rows[j]["departmentname"].ToString();
                        treenodeChild.Value = dtProductsCount.Rows[j]["departmentid"].ToString();
                        treenodeChild.NavigateUrl = "Paren.aspx?departmentid=" + treenodeParent.Value.ToString() + "&parentid=" + treenodeChild.Value.ToString();
                        treenodeParent.ChildNodes.Add(treenodeChild);
                    }
                }
            }
            //TreeNode treenodeParent2 = new TreeNode();
            //treenodeParent2.ImageUrl = "~/images/A1.gif";
            //treenodeParent2.NavigateUrl = "BuMen.aspx";
            //treenodeParent2.Text = "部门管理";
            //this.TreeView1.Nodes.Add(treenodeParent2);
        }
        /// <summary>
        /// 节点展开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {
            foreach (TreeNode treenode in this.TreeView1.Nodes)
            {
                if (treenode.Value != e.Node.Value)
                {
                    treenode.CollapseAll();
                }
            }
        }
    作者:wpf之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    How do I change a .txt file to a .c file?
    [CQOI2007]余数求和
    CSP-J总结&题解
    【CSP游记S】
    [LuoguP1462]通往奥格瑞玛的道路
    归并排序——逆序对
    [NOIP 2011]选择客栈
    [二分图初步]【模板】二分图匹配,匈牙利算法
    [NOIP 2018]旅行
    黑魔法师之门 (magician)-并查集
  • 原文地址:https://www.cnblogs.com/wpf123/p/2347500.html
Copyright © 2011-2022 走看看