The following code example demonstrates how to use this constructor to dynamically add nodes
TreeviewControl.
1 <% @ page Language = "C #" %>
2
3 <SCRIPT runat = "server">
4
5 void page_init (Object sender, eventargs E)
6 {
7
8 If (! Ispostback)
9 {
10
11 // Add the first tree to the Treeview control.
12 createtree ("section 1 ");
13
14 // Add the second tree to the Treeview control.
15 createtree ("section 2 ");
16
17}
18
19}
20
21 void createtree (string nodetext)
22 {
23
24 // create the root node using the default constructor.
25 treenode root = new treenode ();
26 root. Text = nodetext;
27
28 // use the childnodes property of the root treenode to add child nodes.
29 // create the node using the constructor that takes the text parameter.
30 root. childnodes. Add (New treenode ("Topic 1 "));
31
32 // create the node using the constructor that takes the text and value parameters.
33 root. childnodes. Add (New treenode ("Topic 2", "value 2 "));
34
35 // create the node using the constructor that takes the text, value,
36 // and imageurl parameters.
37 root. childnodes. Add (New treenode ("Topic 3", "value 3", "image1.jpg "));
38
39 // create the node using the constructor that takes the text, value,
40 // imageurl, navigateurl, and target parameters.
41 root. childnodes. Add (New treenode ("Topic 4", "value 4", "image1.jpg", "http://www.microsoft.com", "_ blank "));
42
43 // Add the root node to the nodes collection of the Treeview control.
44 dynamictreeview. nodes. Add (Root );
45
46}
47
48 </SCRIPT>
49
50 <HTML>
51
52 <form runat = "server">
53
54 55
56 <asp: Treeview id = dynamictreeview runat = "server" initialexpanddepth = "2" enableclientscript = "false">
57
58 </ASP: Treeview>
59
60 </form>
61
62