• ASP.Net TreeView递归



     

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

     

    using Qhr.QhrService;

     

    namespace Qhr

    {

        public partial class test : System.Web.UI.Page

        {

            Qhr.QhrService.QhrServiceClient proxy = new QhrService.QhrServiceClient();

            QhrService.MyProtocolStructureCollection collection = null;

     

            protected void Page_Load(object sender, EventArgs e)

            {

                if (!IsPostBack)

                {

                    collection = proxy.GetAllProtocolStructure();

                    LoadTree();

                }

            }

     

            private void LoadTree()

            {

                this.TreeView1.Nodes.Clear();

                InitTree(this.TreeView1.Nodes, null);

            }

     

            private void InitTree(TreeNodeCollection Nds, string parentId)

            {

                TreeNode tmpNd = null;

                MyProtocolStructureCollection collectionTemp = new MyProtocolStructureCollection();

                foreach (MyProtocolStructure psTemp in collection)

                {

                    if (psTemp.Pid == parentId)

                    {

                        collectionTemp.Add(psTemp);

                    }

                }

     

                foreach (MyProtocolStructure ps in collectionTemp)

                {

                    tmpNd = new TreeNode();

                    tmpNd.Text = ps.Name;

                    tmpNd.Value = ps.Id;

                    if (parentId == null)

                    {

                        tmpNd.Expanded = true;

                    }

                    else

                    {

                        tmpNd.Expanded = false;

                    }

                    Nds.Add(tmpNd);

                    InitTree(Nds[Nds.Count - 1].ChildNodes, ps.Id);

                }

            }

        }

    }

     

     

  • 相关阅读:
    win10下jdk8和jdk11切换的批处理脚本
    Deeping中使用python连接Oralce报错:Cannot locate a 64-bit Oracle Client library: "./instantclient_21_1/libclntsh.so: file too short"
    Redis作者“不懂”分布式锁【转载】
    搭建nacos高可用集群
    使用spring.config.location与本地配置文件属性不能互补
    protocol buffer应用场景方案想法
    protocol buffer 入门和基本知识
    IDEA快捷键
    软考问题总结
    pandas 使用问题记录
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2278408.html
Copyright © 2020-2023  润新知