RadTreeView NodeTemplate Change Dynamically

3 posts, 0 answers
  1. Bruno
    Bruno avatar
    20 posts
    Member since:
    Sep 2012

    Posted 21 Nov 2011 Link to this post

    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. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Nov 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bruno
    Bruno avatar
    20 posts
    Member since:
    Sep 2012

    Posted 28 Nov 2011 Link to this post

    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
Back to Top