从另一个用户控件在一个用户控件中填充TreeView [英] Populate TreeView in one User Control from another User control

查看:83
本文介绍了从另一个用户控件在一个用户控件中填充TreeView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家,



我有2个用户控件(UC),每个包含一个树视图。这两个UC放在主aspx页面上。单击一个UC中的节点时,我希望第二个UC上的树视图更改内容。如何才能做到这一点?谢谢!

解决方案

1。处理UC1的SelectedNodeChanged事件并尝试在页面中找到第二个用户控件。

2.对于第二个用户控件中的每个子控件,检查是否找到了treeview控件。

3.如果你这样做,以编程方式添加/删除元素。

4.示例代码

ControlCollection ctl = Parent.Controls;



foreach(控制c在ctl中)

{

if(c是UserControl&c.ID!=ctl1)

{



TreeView temp =(TreeView)c .Controls [0];

if(temp!= null)

temp.Nodes.Add(new TreeNode(Treeview Parent 2));

}



}

Experts,

I have 2 user controls (UCs), each contains a treeview. These 2 UCs are placed on the main aspx page. When clicking on a node from the one UC, I want the treeview on the 2nd UC to change the contents. How can this be done? Thanks!

解决方案

1. Handle UC1's SelectedNodeChanged event and try to find the second user control in the page.
2. For each child control in the second user control check if you find treeview control.
3. If you did, add/delete the elements programmatically.
4. Sample code
ControlCollection ctl = Parent.Controls;

foreach (Control c in ctl)
{
if (c is UserControl & c.ID != "ctl1")
{

TreeView temp = (TreeView)c.Controls[0];
if (temp != null)
temp.Nodes.Add(new TreeNode("Treeview Parent 2"));
}

}


这篇关于从另一个用户控件在一个用户控件中填充TreeView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆