Using Database structure to populate TreeView in PreRender

2 posts, 0 answers
  1. Rob
    Rob avatar
    23 posts
    Member since:
    Apr 2013

    Posted 28 Aug 2013 Link to this post

    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.
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 29 Aug 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top