zoukankan      html  css  js  c++  java
  • FineUI控件之树的应用(二)

    一、Tree控件应用

      <f:PageManager ID="PageManager1" runat="server" />
            <f:Tree ID="Tree1" Width="650px" ShowHeader="true" Title="树控件" EnableFrame="true" EnableCollapse="true"
                runat="server">
                <Nodes>
                    <f:TreeNode Text="中国" Expanded="true">
                        <f:TreeNode Text="111" Expanded="true">
                            <f:TreeNode Text="222" NodeID="zhumadian">
                                <f:TreeNode Text="333" Leaf="false" NodeID="suiping">
                                    <f:TreeNode Text="444" Leaf="false" NodeID="huaishu">
                                        <f:TreeNode Text="555" NodeID="chenzhuang">
                                        </f:TreeNode>
                                    </f:TreeNode>
                                </f:TreeNode>
                            </f:TreeNode>
                            <f:TreeNode Text="666" NodeID="luohe" />
                        </f:TreeNode>
                        <f:TreeNode Text="777" Expanded="true" NodeID="anhui">
                            <f:TreeNode Text="888" Expanded="true" NodeID="hefei">
                                <f:TreeNode Text="999" NodeID="golden">
                                </f:TreeNode>
                                <f:TreeNode Text="000" NodeID="ustc">
                                </f:TreeNode>
                            </f:TreeNode>
                        </f:TreeNode>
                    </f:TreeNode>
                </Nodes>
            </f:Tree>
    

    二、后台代码 动态生成Tree 帮定数据库

      1   /// <summary>
      2         /// 绑定Tree
      3         /// </summary>
      4         /// <returns></returns>
      5         private DataSet GetDataSet()
      6         {
      7             CommUserBLL bll = new CommUserBLL();
      8             DataSet ds = bll.GetAllList();
      9 
     10             foreach (DataRow row in ds.Tables[0].Rows)
     11             {
     12                 FineUI.TreeNode node = new FineUI.TreeNode();
     13                 if (row.IsNull("PersonGroupID"))
     14                 {
     15                     node.Text = row["CompName"].ToString();
     16                     node.IconUrl = "~/icon/star.png";
     17                     node.Expanded = true;
     18                     node.EnableCheckBox = true;
     19                     node.EnablePostBack = true;
     20                     node.AutoPostBack = true;
     21                     Tree1.Nodes.Add(node);
     22                     LoadTree(node);
     23                 }
     24             }
     25             return ds;
     26         }
     27 
     28         /// <summary>
     29         /// 加载子节点
     30         /// </summary>
     31         /// <param name="treeNode"></param>
     32         private void LoadTree(FineUI.TreeNode treeNode)
     33         {
     34             CommUserBLL bll = new CommUserBLL();
     35             DataSet dept = bll.GetDepetName();
     36             foreach (DataRow row in dept.Tables[0].Rows)
     37             {
     38                 FineUI.TreeNode node2 = new FineUI.TreeNode();
     39                 node2.Expanded = true;
     40                 node2.EnableCheckBox = true;
     41                 node2.EnablePostBack = true;
     42                 node2.AutoPostBack = true;
     43                 node2.IconUrl = "~/icon/star.png";
     44                 node2.Text = row["DeptName"].ToString();
     45 
     46                 treeNode.Nodes.Add(node2);
     47                 LoadPerson(row, node2);
     48             }
     49         }
     50 
     51         /// <summary>
     52         /// 加载叶子节点
     53         /// </summary>
     54         /// <param name="dr"></param>
     55         /// <param name="treeNode"></param>
     56         private void LoadPerson(DataRow dr, FineUI.TreeNode treeNode)
     57         {
     58             CommUserBLL bll = new CommUserBLL();
     59             StringBuilder str = new StringBuilder();
     60             DataSet deptPerson = bll.GetList("  deptname = '" + dr["DeptName"].ToString() + "'");
     61             foreach (DataRow row in deptPerson.Tables[0].Rows)
     62             {
     63                 FineUI.TreeNode node3 = new FineUI.TreeNode();
     64 
     65                 node3.EnablePostBack = true;
     66                 node3.AutoPostBack = true;
     67                 node3.Expanded = true;
     68                 node3.EnableCheckBox = true;
     69 
     70                 node3.IconUrl = "~/icon/star.png";
     71 
     72                 node3.Text = row["PersonName"].ToString() + "(" + row["PhoneNo"].ToString() + ")";
     73                 treeNode.Nodes.Add(node3);
     74             }
     75         }
     76 
     77         /// <summary>
     78         /// 选择节点事件
     79         /// </summary>
     80         /// <param name="sender"></param>
     81         /// <param name="e"></param>
     82         protected void Tree1_NodeCheck(object sender, FineUI.TreeCheckEventArgs e)
     83         {
     84             if (!e.Node.Leaf)
     85             {
     86                 CheckTreeNode(e.Node.Nodes, e.Checked);
     87             }
     88             FineUI.TreeNodeCollection nodes = Tree1.Nodes;
     89 
     90             StringBuilder sbTree = new StringBuilder();
     91 
     92             sbTree = GetTreeNode(nodes, sbTree);
     93             tbxMessPre.Text = sbTree.ToString();
     94         }
     95 
     96         /// <summary>
     97         /// 获得选择节点
     98         /// </summary>
     99         /// <param name="nodes"></param>
    100         /// <param name="strTree"></param>
    101         /// <returns></returns>
    102         private StringBuilder GetTreeNode(FineUI.TreeNodeCollection nodes, StringBuilder strTree)
    103         {
    104             foreach (FineUI.TreeNode node in nodes)
    105             {
    106                 if (node.Leaf)
    107                 {
    108                     if (node.Checked)
    109                     {
    110                         strTree.Append(node.Text.Trim() + ",");
    111                     }
    112                 }
    113                 else
    114                 {
    115                     GetTreeNode(node.Nodes, strTree);
    116                 }
    117             }
    118             return strTree;
    119         }
    120 
    121         /// <summary>
    122         /// 检查选中节点
    123         /// </summary>
    124         /// <param name="nodes"></param>
    125         /// <param name="isChecked"></param>
    126         private void CheckTreeNode(FineUI.TreeNodeCollection nodes, bool isChecked)
    127         {
    128             foreach (FineUI.TreeNode node in nodes)
    129             {
    130                 node.Checked = isChecked;
    131                 if (!node.Leaf)
    132                 {
    133                     CheckTreeNode(node.Nodes, isChecked);
    134                 }
    135             }
    136         }
  • 相关阅读:
    ARM裸机开发(二)中断编程
    Linux汇编与C互相调用
    Java 2009
    MFC对Socket编程的支持
    Thinkpad
    IE9
    ASP.NET MVC学习教材
    sysprep.exe修改SID
    查询显示进度条
    MOSS2007中型服务场管理 教材<02>: SubSite Backup & Restore
  • 原文地址:https://www.cnblogs.com/1312mn/p/3619760.html
Copyright © 2011-2022 走看看