C # example of treenode Constructor (string)

Source: Internet
Author: User

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
Related Article

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.