The Treeview control is very powerful. Today, we are just a glimpse of it.
The following example shows how to bind the Treeview control to the xmldatasource control and display the selected items on the webpage.
First, add an XML file named TV. xml. Write as follows:Code:
<? XML version = "1.0" encoding = "UTF-8"?> <Gen1 text = "Total directory"> <Zil text = "first subdirectory" url = "~ /One/a. aspx "> <sun1 text =" leaf directory page a "url = "~ /One/cone/a. aspx "> <ye text =" B page "url = "~ /One/cone/B. aspx "> </Ye> </sun1> </Zil> <zi2 text =" 2. One directory "url = "~ /Two/a. aspx "> <sun2 text =" Two directory A pages "url = "~ /Two/a. aspx "> </sun2> <sun3 text =" B page "url = "~ /Two/B. aspx "> </sun3> </zi2> </gen1>
In this case, we add a Treeview control on the default. aspx page. We can select its style (elegant and elegant) and then configure its data source. For example:
This is, the interface is displayed as follows:
We add the background code:
Protected void button#click (Object sender, eventargs e) {// print the value of the selected item out if (treeview1.checkednodes. count> 0) {// If any item is selected foreach (treenode tn in treeview1.checkednodes) {// iterate all selected nodes if (TN. childnodes. count> 0) {// if there is a subnode foreach (treenode CTN in TN Under the selected item. childnodes) {// iterate all nodes and read the value response. write (CTN. text + "<br>") ;}} else {// if there are no nodes below, it indicates a page node. Read the value of the Option response directly. write (TN. text + "<br>") ;}}} protected void treeview1_selectednodechanged (Object sender, eventargs e) {label1.text = treeview1.selectednode. text;} protected void treeviewinclutreenodecheckchanged (Object sender, treenodeeventargs e) {label1.text = "you collapsed" + E. node. text;} protected void treeviewinclutreenodeexpanded (Object sender, treenodeeventargs e) {label1.text = "you expanded" + E. node. text;} protected void treeviewinclutreenodecollapsed (Object sender, treenodeeventargs e ){}
Display Effect: