Dynamically add RadPanelBar items that contain dynamic radtreeview

2 posts, 0 answers
  1. steven
    steven avatar
    1 posts
    Member since:
    Mar 2014

    Posted 28 Jan 2015 Link to this post

    So far I have been able to successfully dynamically load a radtreeview inside a radpanelbar. There are just 2 issues i'm facing now and hopefully someone could help me out. 

    Issue 1.

    After a post back (control added to an ajaxmanager) generated from a radpanel item selected event, my radtreeview disappears.

    Issue 2.

    RadTreeView node click event does not fire.

    I will paste brief segments of my code below. 

    ParentChildItems = function that returns a List<Child> object full of children...

    foreach (Child child in ParentChildItems)
                        {
                            RadTreeView treeView = new RadTreeView();
                            RadPanelItem item = new RadPanelItem(child.Display);
                            RadPanelItem itemFolder = new RadPanelItem();
                            item.Value = child.ChildID;
     
                            List<Object> folders = new Child(General.DB).findAllFoldersByDrawer(child.ChildID);
     
                            if (folders.Count > 1)
                            {
                                treeView.ID = child.ChildID + "_tView";
                                treeView.NodeClick += new RadTreeViewEventHandler(treeView_NodeClick);
                                treeView.CheckChildNodes = true;
     
                                RadTreeNodeBinding binding = new RadTreeNodeBinding();
                                binding.Expanded = true;
                                treeView.DataBindings.Add(binding);
                                treeView.DataTextField = "Display";
                                treeView.DataFieldID = "ChildID";
                                treeView.DataValueField = "ChildID";
                                treeView.DataFieldParentID = "ChildChildID";
                                treeView.DataSource = folders;
                                treeView.ShowLineImages = true;
                                treeView.DataBind();
     
                                itemFolder.Controls.Add(treeView);
                                item.Items.Add(itemFolder);
                            }
     
                            pnlDrawers.Items.Add(item);
     
                            if (folders.Count > 1)
                            {
                                AjaxManager.AjaxSettings.AddAjaxSetting(AjaxManager, treeView, RadAjaxLoadingPanel1, UpdatePanelRenderMode.Inline);
                                AjaxManager.AjaxSettings.AddAjaxSetting(pnlDrawers, treeView, RadAjaxLoadingPanel1, UpdatePanelRenderMode.Inline);
                                AjaxManager.AjaxSettings.AddAjaxSetting(treeView, treeView, RadAjaxLoadingPanel1, UpdatePanelRenderMode.Inline);
                            }
                        }


    public class Child
        {
            #region properties
            public string ChildID { get; set; }
            public string ParentID { get; set; }
            public string ChildChildID { get; set; }
            public string Label { get; set; }
            public string FirstName { get; set; }
            public string MName { get; set; }
            public string Lastname { get; set; }       
    }


  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    837 posts

    Posted 02 Feb 2015 Link to this post

    Hello,

    We recommend using templates when adding RadTreeView or other controls to a RadPanelBar, adding it directly to an item might result in unwanted behavior. Templates are a functionality designed specifically for that purpose - embedding controls in a RadPanel item.
    You can find more information on how you can use templates with RadPanelBar in our documentation and we also have a live demo:

    I am also attaching a sample project showing how to add dynamically TreeView nodes to a template. Clicking on a node changes its text.


    Regards,
    Ivan Danchev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top