RadTreeView:How to add controls to a node

While you can always use an item template to customize the appearance of the nodes in a tree view, another
approach is to simply add controls directly to the Controlscollection of a node in the code-behind. This gives
you the power to customize nodes in the code-behind without having to implement an ITemplate class.
The following example illustrates how to add controls to the Controls collection of a node. It adds a color picker
to the nodes of a tree view when the page first loads. Once controls are added to the Controls collection, the
node no longer displays its Textproperty, but instead shows only the controls that were added.

protected void Page_Load(object sender, EventArgs e)
{
// Go through all of the nodes in the tree view
foreach (RadTreeNode node in RadTreeView1.GetAllNodes())
{
// Replace nodes with the text "Color" by a color picker
if (node.Text == "Color")
{
RadColorPicker colors = new RadColorPicker();
colors.ID = node.ID + "_colors";
colors.Preset = ColorPreset.Opulent;
colors.ShowEmptyColor = false;
colors.PreviewColor = false;
// add the color picker to the controls collection
node.Controls.Add(colors);
}
}
}


Gotcha!

Be sure to add the controls every time the page loads, not just when IsPostBackis false.
Controls that are added this way do not persist in the View State.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值