treeview and XML Three-step generation list Tree _ base Application

Source: Internet
Author: User

Just when I was doing tree view tied, I groped for a while, someone on the web said the TreeView binding data source, with what recursive binding what, I do not want to read, I try to write a
I do this, if there is any problem please the Great God Guide, I am a rookie amount.
1: page TreeView called Tvfunction
2: New Adminfunction.xml

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<function name= "Product release" Url= "~/page/leaves/leave.aspx" >
<subfunction name= "Add Product" url= "~/page/leaves/leave.aspx" >
<subfunction name= "Add Product" url= "~/page/leaves/leave.aspx" >
<function name= "message release" Url= "~/page/leaves/leave.aspx" >
<subfunction name= "Add a Message" url= "~/page/leaves/leave.aspx" >
<subfunction name= "Change Message" url= "~/page/leaves/leave.aspx" >

3: Page Bindings

Copy Code code as follows:

Initialize the tree structure of the function
private void Initfunction ()
XmlDocument xmldoc = new XmlDocument ();
String Xmlpath = "~/adminfunction.xml";
Xmlpath = Server.MapPath (Xmlpath);
XmlDoc. Load (Xmlpath);
XmlNode root = xmldoc. DocumentElement;

foreach (XmlNode node in root). ChildNodes)
Gets the information display of the parent node (frivolous-scholar)
XmlElement x1 = node as XmlElement;
String name = x1. GetAttribute ("name");
String url = x1. GetAttribute ("url");
TreeNode tn = new TreeNode ();
Tn. Text = name;
Tn. NavigateUrl = URL;
foreach (XmlNode subnode in X1. ChildNodes)
XmlElement subxmlemt = subnode as XmlElement;
String subname = Subxmlemt.getattribute ("name");
String suburl = Subxmlemt.getattribute ("url");
TreeNode subtn = new TreeNode ();
Subtn. Text = SubName;
Subtn. NavigateUrl = Suburl;
Tn. Childnodes.add (SUBTN);

TvFunction.Nodes.Add (TN);


4: Display effects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.