RadTreeView:How to add controls to a node

来源:互联网 发布:纳美旅游知乎 编辑:程序博客网 时间:2024/06/05 17:05

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 viewforeach (RadTreeNode node in RadTreeView1.GetAllNodes()){// Replace nodes with the text "Color" by a color pickerif (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 collectionnode.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.

原创粉丝点击