Tree:

  1. namespace ECTECH.NorthSJ.Web.SysData
  2. {
  3. public partial class testTree : BasePage
  4. {
  5. protected int roleId = ;
  6.  
  7. protected void Page_Load(object sender, EventArgs e)
  8. {
  9. if(!IsPostBack)
  10. {
  11. List<Model.Funcs> list = new BLL.RoleFuncs().GetRFunc("", roleId);
  12. foreach(Model.Funcs func in list)
  13. {
  14. FineUI.TreeNode node = new TreeNode() { Text = func.Name, NodeID = func.ID.ToString(), Leaf = false, EnableCheckBox=true };
  15. LoadChildNode(func.FuncCode,roleId, node);
  16. tree1.Nodes.Add(node);
  17. }
  18. }
  19. }
  20.  
  21. private void LoadChildNode(string parentCode, int roleId,TreeNode node)
  22. {
  23. List<Model.Funcs> list = new BLL.RoleFuncs().GetRFunc(parentCode, roleId);
  24. foreach (Model.Funcs func in list)
  25. {
  26. TreeNode nodeChild = new TreeNode() { Text = func.Name, NodeID = func.ID.ToString(), Leaf = true, EnableCheckBox = true };
  27. node.Nodes.Add(nodeChild);
  28. }
  29. }
  30.  
  31. protected void btn1_Click(object sender, EventArgs e)
  32. {
  33. string[] ids = tree1.SelectedNodeIDArray;
  34. string idStr = string.Join(",", ids);
  35. lbResult.Text = idStr;
  36. }
  37.  
  38. }

Form:

  1. <form id="form1" runat="server">
  2. <div>
  3. <x:PageManager ID="PageManager1" AutoSizePanelID="RegionPanel1" runat="server">
  4. </x:PageManager>
  5. <x:Tree ID="tree1" EnableMultiSelect="true" runat="server"></x:Tree>
  6. <x:Button ID="btn1" Text="确定" runat="server" OnClick="btn1_Click"></x:Button>
  7. <x:Label ID="lbResult" EncodeText="false" runat="server"></x:Label>
  8. </div>
  9. </form>

树节点,绑定到DataTable:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6.  
  7. using System.Data;
  8. using FineUI;
  9.  
  10. namespace Test_Web1
  11. {
  12. public partial class TreeTable : System.Web.UI.Page
  13. {
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. if(! IsPostBack)
  17. {
  18. LoadData();
  19. }
  20. }
  21.  
  22. private void LoadData()
  23. {
  24. DataTable dt = CreateTable();
  25. DataSet ds = new DataSet();
  26. ds.Tables.Add(dt);
  27. ds.Relations.Add("treeRelation", ds.Tables[].Columns["ID"],ds.Tables[].Columns["PID"]);
  28.  
  29. foreach(DataRow row in ds.Tables[].Rows)
  30. {
  31. if(row["PID"]==DBNull.Value)
  32. {
  33. TreeNode node = new TreeNode();
  34. node.Text = row["Name"].ToString();
  35. node.NodeID = row["ID"].ToString();
  36. node.Expanded = true;
  37. Tree1.Nodes.Add(node);
  38.  
  39. ResolveSubTree(row, node);
  40. }
  41. }
  42. }
  43.  
  44. private void ResolveSubTree(DataRow row, TreeNode node)
  45. {
  46. DataRow[] rows = row.GetChildRows("treeRelation");
  47. if(rows.Length>)
  48. {
  49. foreach(DataRow r in rows)
  50. {
  51. TreeNode n = new TreeNode();
  52. n.Text = r["Name"].ToString();
  53. n.NodeID = r["ID"].ToString();
  54. n.ParentNode = node;
  55. node.Nodes.Add(n);
  56.  
  57. ResolveSubTree(r, n);
  58. }
  59. }
  60. }
  61.  
  62. public DataTable CreateTable()
  63. {
  64. DataTable dt = new DataTable();
  65. dt.Columns.Add("ID", typeof(string));
  66. dt.Columns.Add("Name", typeof(string));
  67. dt.Columns.Add("PID", typeof(string));
  68.  
  69. DataRow row = dt.NewRow();
  70. row["ID"] = "";
  71. row["Name"] = "四川省";
  72. row["PID"] = DBNull.Value;
  73. dt.Rows.Add(row);
  74.  
  75. row = dt.NewRow();
  76. row["ID"] = "";
  77. row["Name"] = "江苏省";
  78. row["PID"] = DBNull.Value;
  79. dt.Rows.Add(row);
  80.  
  81. row = dt.NewRow();
  82. row["ID"] = "";
  83. row["Name"] = "苏州市";
  84. row["PID"] = "";
  85. dt.Rows.Add(row);
  86.  
  87. row = dt.NewRow();
  88. row["ID"] = "";
  89. row["Name"] = "常州市";
  90. row["PID"] = "";
  91. dt.Rows.Add(row);
  92.  
  93. row = dt.NewRow();
  94. row["ID"] = "";
  95. row["Name"] = "镇江市";
  96. row["PID"] = "";
  97. dt.Rows.Add(row);
  98.  
  99. row = dt.NewRow();
  100. row["ID"] = "";
  101. row["Name"] = "无锡市";
  102. row["PID"] = "";
  103. dt.Rows.Add(row);
  104.  
  105. row = dt.NewRow();
  106. row["ID"] = "";
  107. row["Name"] = "达州市";
  108. row["PID"] = "";
  109. dt.Rows.Add(row);
  110.  
  111. row = dt.NewRow();
  112. row["ID"] = "";
  113. row["Name"] = "广元市";
  114. row["PID"] = "";
  115. dt.Rows.Add(row);
  116.  
  117. row = dt.NewRow();
  118. row["ID"] = "";
  119. row["Name"] = "宣汉县";
  120. row["PID"] = "";
  121. dt.Rows.Add(row);
  122.  
  123. row = dt.NewRow();
  124. row["ID"] = "";
  125. row["Name"] = "大竹县";
  126. row["PID"] = "";
  127. dt.Rows.Add(row);
  128.  
  129. return dt;
  130.  
  131. }
  132. }
  133. }

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. VisualStudio卸载后无法再次安装的解决方法

    解决方法如下: 1.删除 Visual Studio 2013 安装目录文件夹 Visual Studio 12.0 2.win+R 输入 %UserProfile%\Appdata\Local\Mi ...

  2. JAVA8新特性——方法引用

    JAVA9都要出来了,JAVA8新特性都没搞清楚,是不是有点掉队哦~ 在Lamda新特性的支持下,JAVA8中可以使用lamda表达式来创建匿名方法.然而,有时候我们仅仅是需要调用一个已存在的方法(如 ...

  3. Groovy 配置环境变量

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/70313790 本文出自[赵彦军的博客] 概念 Groovy 配置环境变量 开发工具 ...

  4. js的深拷贝特别注意this的深拷贝

    原生的,jquery的extend,和angular的copy 我们深拷贝的根本原因是为了不改变原来对象的值. <script type="text/javascript"& ...

  5. Canvas - Web API

    <canvas> 是 HTML5 新增的元素,可用于通过使用JavaScript中的脚本来绘制图形.例如,它可以用于绘制图形,制作照片,创建动画,甚至可以进行实时视频处理或渲染. Mozi ...

  6. phalcon: 开启模板缓存和缓存路径

    /** * 设置view */ $di->set('view', function () use ($config) { $view = new \Phalcon\Mvc\View(); $vi ...

  7. jQuery实现表格冻结行和列

    前几天,遇到一个需求是要将表格的前几行和前几列冻结即固定,就是在有滚动条的情况下,保持那几行和那几列固定,这个需求其实是一个非常常见的需求,因为在涉及好多行和列时,在拖动滚动条时,我们需要知道每行每列 ...

  8. django 使用多说 评论系统

    效果图 方法:登录多说网站,创建站点.然后有下面的提示 ************************************************* 复制以下代码,并粘帖到您网页代码<bo ...

  9. hdu 5238 Calculator(线段树,中国剩余定理¥)

    Calculator Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  10. HDU 1711 kmp+离散化

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/Other ...