zoukankan      html  css  js  c++  java
  • 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);

                }

            }

        }

    }

     

     

  • 相关阅读:
    C++11 序列化库 cereal
    Eigen 3.3.7 数组类(Array)和元素操作
    Java【 final、权限、内部类、引用类型】学习笔记
    Java多态学习笔记
    学习GUI编程第二天笔记
    GUI编程小测试
    第一篇学习笔记(Typora使用手册)
    Spring Boot2 系列教程(九)Spring Boot 整合 Thymeleaf
    Spring Boot2 系列教程(七)理解自动化配置的原理
    Spring Boot2 系列教程(六)自定义 Spring Boot 中的 starter
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2278408.html
Copyright © 2011-2022 走看看