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. 主攻ASP.NET MVC4.0之重生:ASP.NET MVC Web API

    UserController代码: using GignSoft.Models; using System; using System.Collections.Generic; using Syste ...

  2. 0x5C 计数类DP

    cf 559C 考虑到黑色的格子很少,那么我把(1,1)变成黑色,然后按每个黑色格子接近终点的程度排序,计算黑色格子不经过另一个黑色格子到达终点的方案,对于当前的格子,要减去在它右下角的所有方案数(注 ...

  3. 分开统计的sql写法

    DECLARE @StartDate DATETIME= '2017-10-13 00:00:00';DECLARE @EndDate DATETIME= '2017-11-13 23:00:00'; ...

  4. BZOJ3241/UOJ125 [Noi2013]书法家

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  5. Thinkpad个性化设置:F1~F12恢复正常按键,Fn与Ctrl按键互换

    一.F1~F12恢复正常按键 联想Thinkpad的F1~F12键功能与其他笔记本是相反的! 也就是说,如果不按着Fn,按那几个功能键,实现的是属性设置的功能,比如直接按下F1键是静音,F2键是音量降 ...

  6. addslashes及其反函数 stripslashes

    addslashes() 函数返回在预定义字符之前添加反斜杠的字符串. stripslashes() 去掉addslashes 所添加的反斜杠 预定义字符是: 单引号(') 双引号(") 反 ...

  7. 防止xss,sql攻击函数

    <?php //php防注入和XSS攻击通用过滤. //by qq:831937 $_GET && SafeFilter($_GET); $_POST && Sa ...

  8. 15-THREE.JS 方向光

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...

  9. C#中的线程(四)高级话题

    C#中的线程(四)高级话题   Keywords:C# 线程Source:http://www.albahari.com/threading/Author: Joe AlbahariTranslato ...

  10. 28 python 并发编程之多进程

    一 multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程.P ...