TreeNode 构造函数 (String)的C#例子


 下面的代码示例演示如何使用此构造函数将节点动态添加到 TreeView 控件。

 1 None.gif <% @ Page Language = " C# "   %>    
 2 None.gif  
 3 None.gif < SCRIPT runat = " server " >   
 4 None.gif  
 5 None.gif   void  Page_Init(Object sender, EventArgs e)  
 6 ExpandedBlockStart.gifContractedBlock.gif   {  
 7InBlock.gif    
 8InBlock.gif    if(!IsPostBack)  
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    {  
10InBlock.gif  
11InBlock.gif      // Add the first tree to the TreeView control.  
12InBlock.gif      CreateTree("Section 1");  
13InBlock.gif  
14InBlock.gif      // Add the second tree to the TreeView control.  
15InBlock.gif      CreateTree("Section 2");  
16InBlock.gif      
17ExpandedSubBlockEnd.gif    }
  
18InBlock.gif  
19ExpandedBlockEnd.gif  }
  
20 None.gif  
21 None.gif   void  CreateTree(String NodeText)  
22 ExpandedBlockStart.gifContractedBlock.gif   dot.gif {  
23InBlock.gif  
24InBlock.gif    // Create the root node using the default constructor.  
25InBlock.gif    TreeNode root = new TreeNode();  
26InBlock.gif    root.Text = NodeText;  
27InBlock.gif  
28InBlock.gif    // Use the ChildNodes property of the root TreeNode to add child nodes.  
29InBlock.gif    // Create the node using the constructor that takes the text parameter.  
30InBlock.gif    root.ChildNodes.Add(new TreeNode("Topic 1"));  
31InBlock.gif  
32InBlock.gif    // Create the node using the constructor that takes the text and value parameters.  
33InBlock.gif    root.ChildNodes.Add(new TreeNode("Topic 2""Value 2"));  
34InBlock.gif  
35InBlock.gif    // Create the node using the constructor that takes the text, value,   
36InBlock.gif    // and imageUrl parameters.  
37InBlock.gif    root.ChildNodes.Add(new TreeNode("Topic 3""Value 3""Image1.jpg"));  
38InBlock.gif  
39InBlock.gif    // Create the node using the constructor that takes the text, value,   
40InBlock.gif    // imageUrl, navigateUrl, and target parameters.  
41InBlock.gif    root.ChildNodes.Add(new TreeNode("Topic 4""Value 4""Image1.jpg""http://www.microsoft.com""_blank"));  
42InBlock.gif  
43InBlock.gif    // Add the root node to the Nodes collection of the TreeView control.  
44InBlock.gif    DynamicTreeView.Nodes.Add(root);  
45InBlock.gif  
46ExpandedBlockEnd.gif  }
  
47 None.gif  
48 None.gif </ SCRIPT >    
49 None.gif  
50 None.gif < HTML >    
51 None.gif     
52 None.gif     < FORM runat = " server " >    
53 None.gif       
54 None.gif       < H3 > TreeNode Constructor Example </ H3 >    
55 None.gif         
56 None.gif       < ASP:TREEVIEW id = DynamicTreeView runat = " server "  InitialExpandDepth = " 2 "  EnableClientScript = " false " >    
57 None.gif           
58 None.gif       </ ASP:TREEVIEW >    
59 None.gif  
60 None.gif     </ FORM >    
61 None.gif    
62 None.gif

转载于:https://www.cnblogs.com/lsgoodsun/archive/2007/08/11/851746.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值