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.