Controls (3) -- The Treeview control uses the xmldatasource control as the data source for simple binding

Source: Internet
Author: User

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:

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: info-contact@alibabacloud.com 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.