Since the definition of XML documents in the TreeView control in the use of

  In Asp.Net, can be easily used by the Microsoft Internet Exploer Web Controls controls to achieve tree list.    Microsoft provided by the controls set in the package include MultiPage, TabStrip, Toolbar, four Treeview control. 

  These controls on the use of Microsoft's Web site by the detailed description (see: http://www.microsoft.com/china/msdn/archives/library/dnaspp/html/aspnet-usingtreeviewiewebcontrol.asp; http:/ / msdn.microsoft.com / library / default.asp? url = / workshop / webcontrols / overview / overview.asp). 

  Microsoft provided documentation Treeview Control supports XML document as a resource document (XML document structure itself is a tree structure), on the Treeview control can be used in such as XML documents, a lot of information is described in detail (http : / / www.yesky.com/SoftChannel/72342380468043776/20040630/1825811.shtml), is introduced in this paper with another way XML documents to the analysis of Treeview control. 

  The method is because I did not find information in the case in order to facilitate the use of the self-control and a write process, in fact, the use of the time would not have been large, write only for the purpose of learning together. 

  Controls get in this time, I use it is not their understanding, but in order to put myself in the future can be more convenient procedures in the use of, so I decided to adopt the use of XML documents approach to the storage nodes information, So first of all, I constructed a basic XML file format: 

  <? Xml version = "1.0" encoding = "UTF-8"> 
<treeview>
<nodes>
  <text> Root </ text> 
  <link> </ Link> 
  <target> _self </ Target> 
  <description> </ Description> 
<node>
  <text> Test node -1 </ text> 
  <link> / Test1.aspx </ link> 
  <target> MainFrame </ target> 
  <description> </ Description> 
  </ Node> 
<node>
  <text> Test nodes - 2 </ text> 
  <link> / Test2.aspx </ link> 
  <target> _top </ Target> 
  <description> </ Description> 
  </ Node> 
  </ Nodes> 
  </ Treeview> 

  Treeview to root node, the nodes father-node, node to node son.    Which can be nested nodes can be parallel, the only node parallel.    In the definition of good structure, the most important is how the analysis.    Below are the specific code: 

  / / / 


  / / / TreeViewParse TreeView Parser, XML document read from the node values 
  / / / Document XML documents 
  / / / TreeView Microsoft.Web.UI.WebControls.TreeView 
  / / / 

  Private void TreeViewParse (System.Xml.XmlNode document, Microsoft.Web.UI.WebControls.TreeView treeView) 
  ( 
  If (document.Name! = "Treeview") return; 
  Foreach (System.Xml.XmlNode node in document.ChildNodes) 
  ( 
  If (node.Name! = "Nodes") return; 
  This.NodesParse (node, treeView, null); 
  ) 
  ) 

  / / / 


  / / / NodesParse Nodes Parser, XML document reader from the main node of 
  / / / Document XML documents 
  / / / TreeView Microsoft.Web.UI.WebControls.TreeView 
  / / / Father-node treeNode 
  / / / 

  Private void NodesParse (System.Xml.XmlNode document, Microsoft.Web.UI.WebControls.TreeView treeView, Microsoft.Web.UI.WebControls.TreeNode treeNode) 
  ( 
  If (document.Name! = "Nodes") return; 
  Microsoft.Web.UI.WebControls.TreeNode child = new Microsoft.Web.UI.WebControls.TreeNode (); 
  Foreach (System.Xml.XmlNode node in document.ChildNodes) 
  ( 
  String name = (node.Name! = Null? Node.Name: ""); 
  / / Child.ID node.Name + = "_" + treeView.Nodes.Count.ToString (); 
  Switch (name.Trim (). ToLower ()) 
  ( 
  Case "text": 
  Child.Text = node.InnerText; 
  Break; 
  Case "link": 
  Child.NavigateUrl = node.InnerText; 
  Break; 
  Case "target": 
  Child.Target = node.InnerText; 
  Break; 
  Case "nodes": 
  NodesParse (node, treeView, child); 
  Break; 
  Case "node": 
  NodeParse (node, treeView, child); 
  Break; 
  ) 
  ) 
  If (treeNode == null) treeView.Nodes.Add (child); 
  Else treeNode.Nodes.Add (child); 
  ) 

  / / / 


  / / / NodeParse Node Parser, XML documents from the node value of reading 
  / / / Document XML documents 
  / / / TreeView Microsoft.Web.UI.WebControls.TreeView 
  / / / Father-node treeNode 
  / / / 

  Private void NodeParse (System.Xml.XmlNode document, Microsoft.Web.UI.WebControls.TreeView treeView, Microsoft.Web.UI.WebControls.TreeNode treeNode) 
  ( 
  Microsoft.Web.UI.WebControls.TreeNode child = new Microsoft.Web.UI.WebControls.TreeNode (); 
  Foreach (System.Xml.XmlNode node in document.ChildNodes) 
  ( 
  String name = (node.Name! = Null? Node.Name: ""); 
  Switch (name.Trim (). ToLower ()) 
  ( 
  Case "text": 
  Child.Text = node.InnerText; 
  Break; 
  Case "link": 
  Child.NavigateUrl = node.InnerText; 
  Break; 
  Case "target": 
  Child.Target = node.InnerText; 
  Break; 
  Case "nodes": 
  NodesParse (node, treeView, child); 
  Break; 
  ) 
  ) 
  TreeNode.Nodes.Add (child); 
  ) 

  Following is the use of methods: 

  Private Microsoft.Web.UI.WebControls.TreeView MSTreeView = new Microsoft.Web.UI.WebControls.TreeView (); 
  System.Xml.XmlDocument document = new System.Xml.XmlDocument (); / / 
  Document.Load (System.Web.HttpContext.Current.Server.MapPath (this.XmlDocument)); 
  MSTreeView.Nodes.Clear (); 
  TreeViewParse (document.DocumentElement, MSTreeView); 

  Here, the basic conclusion, it might be time in the pages display correctly on its own definition of the XML document directory tree, but I do not think that convenience, so be consolidated into a component, so only in the use of the time need to drag and drop page…… but later when looking for information found itself on the fact Treeview Control XML document can be used directly (http://www.yesky.com/SoftChannel/72342380468043776/20040630/1825811.shtml ).    Therefore, this method can only be used to study a section of the code! 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags: ,

Releated Articles


0 Comments to “Since the definition of XML documents in the TreeView control in the use of”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.