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

TreeList does not return any results when DataKeyNames is of type string

1 Answer 71 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 16 Dec 2013, 06:21 PM
I am having an issue with TreeList not returning any results whenever I use a string DataKeyNames value. For type int it works as expected.

For the sake of this example, I used an int key but simply added a facade string GET on top of it to verify that once string data type is used it fails.

Am I doing something incorrectly?



Complete ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TreeListStringKey.aspx.cs" Inherits="LiveExamples_Services_Audit_TreeListStringKey" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <rei:REIRadScriptManager ID="REIRadScriptManager1" runat="server" ScriptMode="Release" LoadScriptsBeforeUI="true">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        </Scripts>
    </rei:REIRadScriptManager>
    <div>
        <telerik:RadTreeList ID="tree" runat="server" OnNeedDataSource="Tree_NeedDataSource" ParentDataKeyNames="RealParentId" DataKeyNames="RealId"
            AllowPaging="true" PageSize="1000" AutoGenerateColumns="false" AllowSorting="true" EnableEmbeddedSkins="false" Skin="EHB">
            <Columns>
                <telerik:TreeListBoundColumn UniqueName="SectionName" DataField="SectionName" HeaderText="Section" />
                <telerik:TreeListBoundColumn UniqueName="ActionTaken" DataField="ActionTaken" HeaderText="Action" />
                <telerik:TreeListTemplateColumn UniqueName="ModifiedDate" HeaderText="Modified Date">
                    <ItemTemplate>
                        <%# (DateTime)Eval("ModifiedDate") == DateTime.MinValue ? "" : Eval("ModifiedDate") %>
                    </ItemTemplate>
                </telerik:TreeListTemplateColumn>
                <telerik:TreeListBoundColumn UniqueName="ModifiedBy" DataField="ModifiedBy" HeaderText="Modified By" />
                <telerik:TreeListBoundColumn UniqueName="Value" DataField="Value" HeaderText="Value" HeaderStyle-Width="45%" />
            </Columns>
        </telerik:RadTreeList>
    </div>
    </form>
</body>
</html>



COMPLETE ASPX.CS
using System;
using System.Collections.Generic;
using System.Globalization;
using Telerik.Web.UI;
 
public partial class LiveExamples_Services_Audit_TreeListStringKey : System.Web.UI.Page
{
    public class FlatRevision
    {
        public int Id { get; set; }
        public int ParentId { get; set; }
 
        public string RealId { get { return Id.ToString(CultureInfo.InvariantCulture); } }
        public string RealParentId { get { return ParentId.ToString(CultureInfo.InvariantCulture); } }
 
        //public double RealId { get { return (double)Id; } }
        //public double RealParentId { get { return (double)ParentId; } }
 
 
        public string SectionName { get; set; }
        public DateTime ModifiedDate { get; set; }
        public string ModifiedBy { get; set; }
        public string Value { get; set; }
        public string ActionTaken { get; set; }
        public RevType Type { get; set; }
    }
    public enum RevType
    {
        Section = 1,
        Revision = 2
    }
 
 
    protected void Tree_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
    {
        tree.DataSource = new List<FlatRevision>
            {
                //sv report
                new FlatRevision { Id = 1, ParentId = 0, SectionName = "Site Visit Report", Type = RevType.Section },
                new FlatRevision { Id = 2, ParentId = 1, SectionName = "Key Findings", Type = RevType.Section },
                //kf r1
                //new FlatRevision { Id = 3, ParentId = 2, SectionName = "Revision", Type = RevType.Section, ModifiedBy = "Willis", ModifiedDate = DateTime.Now.AddDays(-2) }, //removing "revision" rows per Venkat
                new FlatRevision { Id = 4, ParentId = 2, SectionName = "Key Finding - ADAP", Type = RevType.Section, Value="Type: ADAP", ActionTaken = "Updated"},
                new FlatRevision { Id = 5, ParentId = 2, SectionName = "Key Finding - Financial Assessment", Type = RevType.Section, Value="Type: Financial Assessment", ActionTaken = "Updated" },
                //kf r2
                //new FlatRevision { Id = 6, ParentId = 2, SectionName = "Revision", Type = RevType.Section, ModifiedBy = "Jimmy", ModifiedDate = DateTime.Now.AddDays(-1)},//removing "revision" rows per Venkat
                new FlatRevision { Id = 7, ParentId = 2, SectionName = "Key Finding - Financial Review", Type = RevType.Section, Value="Type: Financial Review", ActionTaken = "Added" },
                 
 
                //sv questionnaire
                new FlatRevision { Id = 8, ParentId = 0, SectionName = "Post Site Visit Questionnaire", Type = RevType.Section },
                new FlatRevision { Id = 9, ParentId = 8, SectionName = "1. Were there any updates made to the site visit agenda at the entrance conference with the organization? ", Type = RevType.Section },
 
                //simple checklist revision
                //new FlatRevision { Id = 10, ParentId = 9, SectionName = "Revision", Type = RevType.Section, ModifiedBy = "Jasper", ModifiedDate = DateTime.Now.AddDays(-4).AddMinutes(-29) }, //removing "revision" rows per Venkat
                //new FlatRevision { Id = 11, ParentId = 10, SectionName = "Checklist Question", Type = RevType.Section },
                new FlatRevision { Id = 12, ParentId = 9, SectionName = "Answer", Type = RevType.Section, Value = "Yes", ActionTaken = "Updated"},
                new FlatRevision { Id = 13, ParentId = 9, SectionName = "Comment", Type = RevType.Section, Value = "pajama pajama pajama pajama pajama pajama pajama pajama pajama pajama", ActionTaken = "Updated"},
                new FlatRevision { Id = 14, ParentId = 9, SectionName = "Agenda Documents", Type = RevType.Section},
                new FlatRevision { Id = 15, ParentId = 14, SectionName = "Document - 'Bananas.txt'", Type = RevType.Section, ActionTaken = "Added"},
                new FlatRevision { Id = 16, ParentId = 15, SectionName = "Document Name", Type = RevType.Section, Value="Bananas.txt"},
                new FlatRevision { Id = 17, ParentId = 15, SectionName = "Document Size", Type = RevType.Section, Value="5kb"},
                new FlatRevision { Id = 18, ParentId = 15, SectionName = "Document Description", Type = RevType.Section, Value="This is the file that contains useful information about bananas."},
                new FlatRevision { Id = 19, ParentId = 14, SectionName = "Document - 'Fish.txt'", Type = RevType.Section, ActionTaken = "Updated"},
                new FlatRevision { Id = 20, ParentId = 19, SectionName = "Document Name", Type = RevType.Section, Value="Fish.txt"},
                new FlatRevision { Id = 21, ParentId = 19, SectionName = "Document Size", Type = RevType.Section, Value="332kb"},
                new FlatRevision { Id = 22, ParentId = 19, SectionName = "Document Description", Type = RevType.Section, Value="All about fish."},
            };
    }
}

1 Answer, 1 is accepted

Sort by
0
Justin
Top achievements
Rank 1
answered on 16 Dec 2013, 10:44 PM
Stumbled onto the answer myself. The documentation explains it: TreeList Structure

I overlooked a rather important detail:

  1. If the key fields are of value type or string, the root items are either:
    • items with ParentKeyValue set to the default value of the type
    • items for which the parent key value is equal to the key value
    Items with parent key value which does not fulfil the above requirement, and have no parent item (e.g. their parent key value does not correspond to any other item key value) are not included in the resolved data source of the treelist at all.
  2. If the key fields are complex objects, a recursive check on their properties is performed until the above rule is met.

Once I modified my code to use default(T) wherever root elements have a parent, things began working.
Tags
TreeList
Asked by
Justin
Top achievements
Rank 1
Answers by
Justin
Top achievements
Rank 1
Share this question
or