A simple demo selects the selected node:
Page code:
Protected void btnshow_click (Object sender, eventargs E)
...{
Treenode node = new treenode ("root ");
TVshow. nodes. Add (node );
Treenode childnode1 = new treenode ("childnode1 ");
Treenode childnode2 = new treenode ("childnode2 ");
Treenode childnode3 = new treenode ("childnode3 ");
Node. childnodes. Add (childnode1 );
Node. childnodes. Add (childnode2 );
Node. childnodes. Add (childnode3 );
Treenode node2 = new treenode ("root2 ");
TVshow. nodes. Add (node2 );
Treenode childnode1for2 = new treenode ("childnode1for2 ");
Treenode childnode2for2 = new treenode ("childnode1for2 ");
Treenode childnode3for2 = new treenode ("childnode1for2 ");
Node2.childnodes. Add (childnode1for2 );
Node2.childnodes. Add (childnode2for2 );
Node2.childnodes. Add (childnode3for2 );
}
Protected void btnget_click (Object sender, eventargs E)
...{
For (INT I = 0; I <TVshow. nodes. Count; I ++)
...{
If (TVshow. nodes [I]. childnodes. Count> 0) // you can check whether a subnode exists.
...{
Getnode (TVshow. nodes [I]);
}
If (TVshow. nodes [I]. Checked = true) // you can check whether the node is selected.
...{
String S = TVshow. nodes [I]. value. tostring ();
Listbox1.items. Add (s );
}
}
}
Public void getnode (treenode node)
...{
For (INT I = 0; I <node. childnodes. Count; I ++)
...{
If (node. childnodes [I]. childnodes. Count> 0) // you can determine whether a subnode exists.
...{
Getnode (TVshow. nodes [I]); // recursive search
}
If (node. childnodes [I]. Checked = true) // you can check whether the node is selected.
...{
String S = node. childnodes [I]. value. tostring ();
Listbox1.items. Add (s );
}
}
}
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Treeview id = "TVshow" runat = "server" showcheckboxes = "all"> </ASP: Treeview> <br/>
<Asp: button id = "btnshow" runat = "server" text = "show data" onclick = "btnshow_click"/>
<Asp: button id = "btnget" runat = "server" text = "Get Data" onclick = "btnget_click"/>
</Div>
<Asp: ListBox id = "listbox1" runat = "server" Height = "284px" width = "250px">
</ASP: ListBox>
</Form>
</Body>
</Html>