I just found out when I was doing Tree view binding. Some people on the Internet say that TreeView is used to bind data sources and recursively bind data sources. If I don't want to see it, I tried to write
I did this. If you have any questions, please instruct me. I am a cainiao ..
1: Page TreeView is called tvFunction
2: Create adminFunction. xml
Copy codeThe Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Functions>
<Function name = "product release" url = "~ /Page/leaves/leave. aspx ">
<Subfunction name = "add product" url = "~ /Page/leaves/leave. aspx ">
</Subfunction>
<Subfunction name = "add product" url = "~ /Page/leaves/leave. aspx ">
</Subfunction>
</Function>
<Function name = "message publishing" url = "~ /Page/leaves/leave. aspx ">
<Subfunction name = "add message" url = "~ /Page/leaves/leave. aspx ">
</Subfunction>
<Subfunction name = "Modify message" url = "~ /Page/leaves/leave. aspx ">
</Subfunction>
</Function>
</Functions>
3: Page binding
Copy codeThe Code is as follows:
/// <Summary>
/// Initialize the function tree
/// </Summary>
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)
{
// Obtain the information 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 Effect