Tree:

namespace ECTECH.NorthSJ.Web.SysData
{
public partial class testTree : BasePage
{
protected int roleId = ; protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
List<Model.Funcs> list = new BLL.RoleFuncs().GetRFunc("", roleId);
foreach(Model.Funcs func in list)
{
FineUI.TreeNode node = new TreeNode() { Text = func.Name, NodeID = func.ID.ToString(), Leaf = false, EnableCheckBox=true };
LoadChildNode(func.FuncCode,roleId, node);
tree1.Nodes.Add(node);
}
}
} private void LoadChildNode(string parentCode, int roleId,TreeNode node)
{
List<Model.Funcs> list = new BLL.RoleFuncs().GetRFunc(parentCode, roleId);
foreach (Model.Funcs func in list)
{
TreeNode nodeChild = new TreeNode() { Text = func.Name, NodeID = func.ID.ToString(), Leaf = true, EnableCheckBox = true };
node.Nodes.Add(nodeChild);
}
} protected void btn1_Click(object sender, EventArgs e)
{
string[] ids = tree1.SelectedNodeIDArray;
string idStr = string.Join(",", ids);
lbResult.Text = idStr;
} }

Form:

    <form id="form1" runat="server">
<div>
<x:PageManager ID="PageManager1" AutoSizePanelID="RegionPanel1" runat="server">
</x:PageManager>
<x:Tree ID="tree1" EnableMultiSelect="true" runat="server"></x:Tree>
<x:Button ID="btn1" Text="确定" runat="server" OnClick="btn1_Click"></x:Button>
<x:Label ID="lbResult" EncodeText="false" runat="server"></x:Label>
</div>
</form>

树节点,绑定到DataTable:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI; using System.Data;
using FineUI; namespace Test_Web1
{
public partial class TreeTable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(! IsPostBack)
{
LoadData();
}
} private void LoadData()
{
DataTable dt = CreateTable();
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.Relations.Add("treeRelation", ds.Tables[].Columns["ID"],ds.Tables[].Columns["PID"]); foreach(DataRow row in ds.Tables[].Rows)
{
if(row["PID"]==DBNull.Value)
{
TreeNode node = new TreeNode();
node.Text = row["Name"].ToString();
node.NodeID = row["ID"].ToString();
node.Expanded = true;
Tree1.Nodes.Add(node); ResolveSubTree(row, node);
}
}
} private void ResolveSubTree(DataRow row, TreeNode node)
{
DataRow[] rows = row.GetChildRows("treeRelation");
if(rows.Length>)
{
foreach(DataRow r in rows)
{
TreeNode n = new TreeNode();
n.Text = r["Name"].ToString();
n.NodeID = r["ID"].ToString();
n.ParentNode = node;
node.Nodes.Add(n); ResolveSubTree(r, n);
}
}
} public DataTable CreateTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("PID", typeof(string)); DataRow row = dt.NewRow();
row["ID"] = "";
row["Name"] = "四川省";
row["PID"] = DBNull.Value;
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "江苏省";
row["PID"] = DBNull.Value;
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "苏州市";
row["PID"] = "";
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "常州市";
row["PID"] = "";
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "镇江市";
row["PID"] = "";
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "无锡市";
row["PID"] = "";
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "达州市";
row["PID"] = "";
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "广元市";
row["PID"] = "";
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "宣汉县";
row["PID"] = "";
dt.Rows.Add(row); row = dt.NewRow();
row["ID"] = "";
row["Name"] = "大竹县";
row["PID"] = "";
dt.Rows.Add(row); return dt; }
}
}

WebForm中创建树节点TreeNode的更多相关文章

  1. webform 创建树

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...

  2. PAT树_层序遍历叶节点、中序建树后序输出、AVL树的根、二叉树路径存在性判定、奇妙的完全二叉搜索树、最小堆路径、文件路由

    03-树1. List Leaves (25) Given a tree, you are supposed to list all the leaves in the order of top do ...

  3. [LeetCode] Inorder Successor in BST 二叉搜索树中的中序后继节点

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. No ...

  4. DS Tree 已知后序、中序 => 建树 => 求先序

    注意点: 和上一篇的DS Tree 已知先序.中序 => 建树 => 求后序差不多,注意的地方是在aftorder中找根节点的时候,是从右往左找,因此递归的时候注意参数,最好是拿纸和笔模拟 ...

  5. DS Tree 已知先序、中序 => 建树 => 求后序

    参考:二叉树--前序和中序得到后序 思路历程: 在最初敲的时候,经常会弄混preorder和midorder的元素位置.大体的思路就是在preorder中找到根节点(根节点在序列的左边),然后在mid ...

  6. 【Ext.Net学习笔记】01:在ASP.NET WebForm中使用Ext.Net

    Ext.NET是基于跨浏览器的ExtJS库和.NET Framework的一套支持ASP.NET AJAX的开源Web控件,包含有丰富的Ajax运用,其前身是Coolite. 下载地址:http:// ...

  7. Ext.Net学习笔记01:在ASP.NET WebForm中使用Ext.Net

    Ext.Net是一个对ExtJS进行封装了的.net控件库,可以在ASP.NET WebForm和MVC中使用.从今天开始记录我的学习笔记,这是第一篇,今天学习了如何在WebForm中使用Ext.Ne ...

  8. [Swift]LeetCode285. 二叉搜索树中的中序后继节点 $ Inorder Successor in BST

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Th ...

  9. [转]WebForm中使用MVC

    本文转自:https://www.cnblogs.com/encoding/articles/3556046.html 前言 掐指一算,3年没写博了,好懒的说... 众所周知,MVC现在越来越火了,不 ...

随机推荐

  1. blast+简介

    blast+有三大工具类型: 功能 search database filter 命令 blastn, blastp, blastx, tblastx, tblastn, psiblast, rpsb ...

  2. linux下的cacti安装(centos7)

    1 cacti运行环境准备 cacti需要php+apache+mysql+snmp+RRDTool,以及cacti本身.cacti本体是用php开发的网站,通过snmp对远端设备信息进行采集.apa ...

  3. Deep Learning概述

    1.深度学习发展简史 2.三步实现深度学习 2.1Neural Network 神经网络由模仿脑部神经系统发展而来,一个节点称为一个“Neuron”,包括连接在节点上面的weights和biases. ...

  4. web.xml里报错:Multiple annotations found at this line:

    在web.xml 中添加错误页面配置,出现了这个报错 具体情况是这样的: 错误信息: Multiple annotations found at this line: - cvc-complex-ty ...

  5. Elasticsearch Suggester 学习

    suggester搜索就像百度搜索框中的提示类似. Elasticsearch 中提供类似的搜索功能. 答案就在Suggesters API. Suggesters基本的运作原理是将输入的文本分解为t ...

  6. nova instance启动中的同步与异步

    instance create:nova/api/servers.create -- self.compute_api.create -- self.compute_task_api.build_in ...

  7. windows7下cmd窗口使用ssh命令

    http://jingyan.baidu.com/article/36d6ed1f931eb31bcf4883dc.html

  8. spring: 使用Aspectj代理EnabelAspectjAutoProxy

    使用JavaConfig的话,可以在配置类的类级别上通过使用EnableAspectJ-AutoProxy注解启用自动代理功能. package ch2.test; import org.aspect ...

  9. vue项目组件的全局注册

    在vue-cli项目中,我们经常会封装自己的组件,并且要在多个界面中引用它,这个时候就需要全局注册组件. 首先我们会封装自己的组件,比如twoDimensionTable文件夹下的index.vue: ...

  10. 用VMware vSphere搭建虚拟化平台

    核心组件 vSphere是一款可以独立安装和运行在祼机上的系统,因此与其他我们以往见过的VMware Workstation 软件不同的是它不再依存于宿主操作系统之上.在ESXi安装好以后,我们可以通 ...