RadTreeView Only display ROOT nodes

2 posts, 0 answers
  1. Oğulcan
    Oğulcan avatar
    1 posts
    Member since:
    Nov 2017

    Posted 24 Nov Link to this post

    Hello, i have really simple RadTreeView control. 

    but there is an issue, nodes only display if they have "0" ParentID. I put the code like telerik's examples and also table content is correct.

    Why i cant put any child nodes which their ParentID is ParentID > 0


    var ds = db.Finding.AsQueryable().ToList();
     
    treeView.DataTextField = "VulnerabilityCode";
    treeView.DataValueField = "ScanId";
    treeView.DataFieldID = "Id";
    treeView.DataFieldParentID = "ParentId"; // only shows where this value is ZERO
    treeView.DataSource = ds;
    treeView.DataBind();

     

    <telerik:RadPane runat="server" Scrolling="None">
                            <telerik:RadSplitter runat="server" Orientation="Horizontal">
                                <telerik:RadPane runat="server">
                                    <telerik:RadTreeView ID="RadTreeView2" IsExpanded="True" runat="server" Skin="WebBlue" Height="600px" Width="100%">
                                    </telerik:RadTreeView>
                                </telerik:RadPane>
    ...

     

  2. Peter Milchev
    Admin
    Peter Milchev avatar
    300 posts

    Posted 29 Nov Link to this post

    Hello Oğulcan,

    Would you please check again if the Data in the ds collection is correct? The ParentId value has to be either 0 (or null, when the type of Id is string) or an Id of an existing node.

    Please find attached a sample project that works as expected - https://www.screencast.com/t/IFk8TPRVJ61.

    <telerik:RadTreeView ID="treeView" IsExpanded="True" runat="server" Height="600px" Width="100%">
    </telerik:RadTreeView>
    public static int index { get; set; }
     
    public class Vulnerability
    {
        public string VulnerabilityCode { get; set; }
        public int ScanID { get; set; }
        public int Id { get; set; }
        public int ParentId { get; set; }
     
    }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        var ds = GetVulnerabilities();
     
        treeView.DataTextField = "VulnerabilityCode";
        treeView.DataValueField = "ScanId";
        treeView.DataFieldID = "Id";
        treeView.DataFieldParentID = "ParentId"; // only shows where this value is ZERO
        treeView.DataSource = ds;
        treeView.DataBind();
    }
     
    private List<Vulnerability> GetVulnerabilities()
    {
        var roots = new List<Vulnerability>();
        var allItems = new List<Vulnerability>();
        index = 1;
        var random = new Random();
        for (int i = 0; i < 5; i++)
        {
            roots.Add(new Vulnerability() { Id = index, ParentId = 0, ScanID = random.Next(), VulnerabilityCode = "Vulnerability " + index });
            index++;
        }
        allItems.AddRange(roots);
     
        var firstLevel = AddChildren(roots);
        allItems.AddRange(firstLevel);
     
        var secondLevel = AddChildren(firstLevel);
        allItems.AddRange(secondLevel);
     
        return allItems;
    }
     
    private static List<Vulnerability> AddChildren(List<Vulnerability> roots)
    {
        var random = new Random();
        var items = new List<Vulnerability>();
        foreach (var item in roots)
        {
            for (int i = 0; i < 5; i++)
            {
                items.Add(new Vulnerability() { Id = index, ParentId = item.Id, ScanID = random.Next(), VulnerabilityCode = "Vulnerability " + index });
                index++;
            }
        }
     
        return items;
    }

    Regards,
    Peter Milchev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top