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

Using Database structure to populate TreeView in PreRender

1 Answer 94 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 28 Aug 2013, 06:08 PM
Hi, I am trying to use database structure to populate Rad TreeView on PreRender after new item added, but I cannot see new node until I refresh the page. Please, help.

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 29 Aug 2013, 02:11 PM
Hello,

As far as I understood your scenario, you are trying to add a new node to the RadTreeView node's collection and then add a hierarchy structure of items to the RadTreeView object. Could you please try to use the AppendDataBoundItems="true". This will append the hierarchy structure of items instead of replacing the existing nodes.
//markup code
<telerik:RadTreeView ID="treeview1" runat="server" AppendDataBoundItems="true"
</telerik:RadTreeView>
//code behind
protected void Page_PreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            treeview1.Nodes.Add(new RadTreeNode("added node"));
 
            SiteDataItem[] siteDataBus = new SiteDataItem[] {
               new SiteDataItem("1", null, "Node1"),
               new SiteDataItem("2", null, "Node2"),
               new SiteDataItem("3", "1", "Node 1.1")           
           };
            treeview1.DataTextField = "Text";
            treeview1.DataValueField = "Id";
            treeview1.DataFieldID = "Id";
            treeview1.DataFieldParentID = "ParentID";
            treeview1.DataSource = siteDataBus;
            treeview1.DataBind();
        }
    }


Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
TreeView
Asked by
Rob
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or