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

Dynamically add RadPanelBar items that contain dynamic radtreeview

1 Answer 215 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
steven
Top achievements
Rank 1
steven asked on 28 Jan 2015, 10:00 PM
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; }       
}


1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 02 Feb 2015, 04:24 PM
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.

 
Tags
PanelBar
Asked by
steven
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or