add nodes dynamically with nodetemplates

2 posts, 0 answers
  1. chp
    chp avatar
    11 posts
    Member since:
    Oct 2012

    Posted 13 Jul 2011 Link to this post

    hi i got problem, adding new nodes dynamically.
    the nodetemplates are assigned by the templateneeded event:

    protected void tree_TemplateNeeded(object sender, RadTreeNodeEventArgs e)
    {
     
        ANDNode x=new ANDNode();
     
        e.Node.NodeTemplate = x;
     
    }


    my root node is a dropdownlist and when i change the selected index of the ddl, new child nodes should be added to the node.
    My problem is, that the selectedchangedindex event will be not performed. Do you have an idea, why it will be not performed?

    public class ANDNode : ITemplate
    {
     
        public ANDNode()
        {
     
     
        }
        public void InstantiateIn(System.Web.UI.Control container)
        {
            DropDownList ddl = new DropDownList();
     
            ddl.AutoPostBack = true;
     
            ddl.ID = "ddl"+Guid.NewGuid().ToString();
            ddl.DataBinding+=new EventHandler(ddl_DataBinding);
            ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
             
            
            container.Controls.Add(ddl);
        }
     
        void  ddl_DataBinding(object sender, EventArgs e)
        {
            Global.FillExpressionItems((DropDownList)sender);
        }
     
     
        void ddl_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl = (DropDownList)sender;
     
            RadTreeNode node = (RadTreeNode)ddl.NamingContainer;
            node.ExpandMode = TreeNodeExpandMode.ServerSide;
            node.Expanded = true;
     
            RadTreeNode child = new RadTreeNode();
            child.NodeTemplate = new ANDNode();
            node.Nodes.Add(child);
        }
     
    }
  2. Plamen
    Admin
    Plamen avatar
    3031 posts

    Posted 15 Jul 2011 Link to this post

    Hello Chp,

    It is a little difficult for us to see what is causing the problem, would you please isolate it in a sample project so we can be more helpful.

    Greetings,
    Plamen Zdravkov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top