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"?>
<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 release" Url= "~/page/leaves/leave.aspx" >
<subfunction name= "Add a Message" url= "~/page/leaves/leave.aspx" >
</subfunction>
<subfunction name= "Change Message" url= "~/page/leaves/leave.aspx" >
</subfunction>
</function>
</functions>
3: Page Bindings
Copy Code code as follows:
<summary>
Initialize the tree structure of the function
</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)
{
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