This is a migrated thread and some comments may be shown as answers.

RadTreeView NodeTemplate Change Dynamically

2 Answers 141 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 21 Nov 2011, 06:31 PM
Hi all,

I am using a RadTreeView and I want to have a functionality as follows: I need to have an option (a button or link) that 
when I click it I get a different view from the RadTreeView. The first view is just having a 'name' field from the database 
in each node, and the alternative view is to have the 'name' and then below the 'description' field also from the database.
Is it possible to change the NodeTemplate Dynamically or is there any simplier way to do this (like for example, having two 
different NodeTemplates and the making one or the other active).

Thanks,
Bruno

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Nov 2011, 11:48 AM
Hello,

You can try the following code snippet to add NodeTemplate on Button Click.

CS:
protected override void OnInit(EventArgs e)
 {
   treeview.NodeTemplate = new TextBoxTemplate();
   base.OnInit(e);
 }
protected void button1_Click(object sender, EventArgs e)
 {
   treeview.Nodes.Add(new RadTreeNode("root1"));
   treeview.Nodes.Add(new RadTreeNode("root2"));
 }
 class TextBoxTemplate : ITemplate
 {
  public void InstantiateIn(Control container)
   {
    Label label1 = new Label();
    label1.ID = "ItemLabel";
    label1.Text = "Text";
    label1.Font.Size = 10;
    label1.Font.Bold = true;
    container.Controls.Add(label1);
   }
 }

-Shinu.
0
Bruno
Top achievements
Rank 1
answered on 28 Nov 2011, 06:19 PM
Solved with:

protected void CriteriaTree_NodeCreated(object sender, RadTreeNodeEventArgs e)
{
    if (e.Node.Level == 0)
        e.Node.ContextMenuID = "RootContextMenu";
    else
        e.Node.ContextMenuID = "MainContextMenu";
}

Tks
Bruno
Tags
TreeView
Asked by
Bruno
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Bruno
Top achievements
Rank 1
Share this question
or