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);

                }

            }

        }

    }

     

     

  • 相关阅读:
    Nginx作为缓存服务
    Nginx作为代理服务
    ZipUtils zip压缩实现
    getman九桃小说解析油猴脚本
    maven添加代理加速jar包下载
    ffmpeg MP3 flv 视频转mp3
    ActiveMQ配置用户认证信息
    JS实现HTML标签转义及反转义
    删除registry镜像数据,以centos为例
    启动一个带登录账号密码的registry容器
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2278408.html
Copyright © 2011-2022 走看看