内部角度按内角折叠 Oblique> 90度:Obtuse Angled Traingle Oblique< 90度:急性角度滑动 直角三角形 但我想要输出结构如: admin ----------- ------------- | -------------------------- | | 用户学生 | -------------- -------- | | using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.IO;using System.Collections.Generic;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { PopulateTreeview(); } private void PopulateTreeview() { this.tvHierarchyView.Nodes.Clear(); HierarchyTrees hierarchyTrees = new HierarchyTrees(); HierarchyTrees.HTree objHTree=null; using (SqlConnection connection = new SqlConnection("Server = NAGESH2-PC\\SQLEXPRESS; Database = test1; Trusted_Connection = True")) { connection.Open(); using (SqlCommand command = new SqlCommand("SSP_GET_HIERARCHY", connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; SqlDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection); while (reader.Read()) { objHTree=new HierarchyTrees.HTree(); objHTree.LevelDepth = int.Parse(reader["LEVEL_DEPTH"].ToString()); objHTree.NodeID = int.Parse(reader["NODE_ID"].ToString()); objHTree.UnderParent = int.Parse(reader["UNDER_PARENT"].ToString()); objHTree.NodeDescription = reader["NODE_DESCRIPTION"].ToString(); hierarchyTrees.Add(objHTree); } } } foreach (HierarchyTrees.HTree hTree in hierarchyTrees) { HierarchyTrees.HTree parentNode = hierarchyTrees.Find(delegate(HierarchyTrees.HTree emp) { return emp.NodeID == hTree.UnderParent; }); if (parentNode != null) { foreach (TreeNode tn in tvHierarchyView.Nodes) { if (tn.Value == parentNode.NodeID.ToString()) { tn.ChildNodes.Add(new TreeNode(hTree.NodeDescription.ToString(), hTree.NodeID.ToString())); } if (tn.ChildNodes.Count > 0) { foreach (TreeNode ctn in tn.ChildNodes) { RecursiveChild(ctn, parentNode.NodeID.ToString(), hTree); } } } } else { tvHierarchyView.Nodes.Add(new TreeNode(hTree.NodeDescription, hTree.NodeID.ToString())); } } tvHierarchyView.ExpandAll(); } public void RecursiveChild(TreeNode tn, string searchValue, HierarchyTrees.HTree hTree) { if (tn.Value == searchValue) { tn.ChildNodes.Add(new TreeNode(hTree.NodeDescription.ToString(), hTree.NodeID.ToString())); } if (tn.ChildNodes.Count > 0) { foreach (TreeNode ctn in tn.ChildNodes) { RecursiveChild(ctn, searchValue,hTree); } } } public class HierarchyTrees : List<hierarchytrees.htree> { public class HTree { private string m_NodeDescription; private int m_UnderParent; private int m_LevelDepth; private int m_NodeID; public int NodeID { get {return m_NodeID;} set { m_NodeID=value; } } public string NodeDescription { get { return m_NodeDescription; } set { m_NodeDescription = value; } } public int UnderParent { get { return m_UnderParent; } set { m_UnderParent = value; } } public int LevelDepth { get { return m_LevelDepth; } set { m_LevelDepth = value; } } } } }output:output is coming like that.Collapse MathematicsMathematicsCollapse AlgebraAlgebraElementary AlgebraAbstract AlgebraLinear AlgebraCollapse GeometryGeometryCollapse TriangleTriangleCollapse By Relative LengthBy Relative LengthCollapse Equilateral TriangleEquilateral TriangleAll Sides are EqualScalene TriangleIsosceles TriangleCollapse By Internal AngleBy Internal AngleOblique > 90 Degree:Obtuse Angled TraingleOblique < 90 Degree:Acute Angled TraingleRight Angled Trianglebut i want output structure like: admin------------------------|--------------------------| |user student |----------------------| |推荐答案 这里的主要错误是:所谓的家谱不能是一棵树(除非你忽略其中一个性别,因为它可能在某些历史中记忆树,主要基于邮件性别)。根据定义,树是没有周期的图形: http://en.wikipedia.org/wiki/ Tree_%28graph_theory%29 [ ^ ]。 家庭关系是一个更通用的结构图,一个有向图(http://en.wikipedia.org/wiki/Directed_graph [ ^ ])因为通常顶点有两个父节点。它在关系中创建循环。 因此,层次结构,层次结构视图,树视图的概念不适用。实际上,您可以考虑将一些子图构建为树,并添加互补关系,以表示完整的图形。 现在,另一个问题是:您正在尝试将数据呈现与可视化演示和UI混合在一起。这是一个糟糕的方法。您应该开发一个纯粹的数据模型,与UI完全无关,并在其上创建一些与您的图形数据绑定的UI。 我希望这些笔记将帮助您检查整个方法,并提供更充分的模型和解决方案。不幸的是,Quick Questions& amp;答案论坛几乎不允许我们为您开发整个架构和设计;我们几乎没有资源。下一步应该是你的。 祝你好运。 -SA The main mistake here is: so called "family tree" cannot be a tree (unless you ignore one of the sexes, as it probably was in some historical "memory trees", which was majorly based on the mail sex). Tree is, by definition, is a "graph without cycles": http://en.wikipedia.org/wiki/Tree_%28graph_theory%29[^].Family relationship is a graph of more general structure, a directed graph (http://en.wikipedia.org/wiki/Directed_graph[^]) just because normally vertices have two parents. It creates cycles in the relationship.Therefore, the concept of hierarchy, hierarchy view, tree view are not applicable. Actually, you could think of building some sub-graph as a tree, and add complementary relationship to it, to represent a full graph.Now, another problem is: you are trying to mix up data presentation with visual presentation and UI. This is a bad approach. You should rather develop a pure data model, totally agnostic to UI, and, on top of it, create some UI bound with your graph data.I hope these notes will help you to review your whole approach and come to more adequate model and solution. Unfortunately, the format of Quick Questions & Answers forum hardly allows us to develop the whole architecture and design for you; we hardly have resources for that. Next move should be yours.Good luck.—SA 检查这些 Asp.net中的树视图 [ ^ ](传销类型树) 动态创建二叉树以显示成员 [ ^ ] 使用Asp.Net绘制二叉树 [ ^ ] Check theseTree View in Asp.net[^](MLM type tree)Creating dynamically Binary Tree to Display Member[^]Draw a Binary Tree using Asp.Net[^] 看到这个.. :) 迭代器模式示例代码 - 族谱 [ ^ ] Tree< t>:在C#中实现非二叉树 [ ^ ] 这些链接只是作为指导,你必须努力......:)see this.. :)Iterator Pattern Example Code—Family Tree[^]Tree<t>: Implementing a Non-Binary Tree in C#[^]those links are only for guidance, you have to work on that... :) 这篇关于如何使用asp.net c#构建族树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-18 18:05