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

[Solved] Treeview with self-referencing composite key

0 Answers 53 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Travis
Top achievements
Rank 1
Travis asked on 28 Apr 2012, 08:14 PM
Hello, I am new to the Telerik suite and to MVC3. I am trying to use the MVC3 Telerik treeview control with a self-referencing composite key, but cannot see any children - code is below

 

@model System.Collections.Generic.IEnumerable<HierarchyMember>
...
@using (Html.BeginForm("Index", "HierarchyMember", FormMethod.Post)) 
{
Html.Telerik().TreeView().Name("Hierarchy") 
    .BindTo(Model as IEnumerable<HierarchyMember>, mappings => 
     {
        mappings.For<HierarchyMember>(binding => binding 
            .ItemDataBound((item, hierarchyMember) =>
            {
                item.Text = hierarchyMember.Description;
                item.Value = hierarchyMember.HierarchyDefinitionId.ToString(); // - 1st column of Composite Key
                item.Value = hierarchyMember.EmployeeId.ToString(); //?? - 2nd column of Composite Key 
                item.Expanded = true; 
            })
            .Children(hierarchyMember => hierarchyMember.HierarchyMember1));
        mappings.For<HierarchyMember>(binding => binding 
           .ItemDataBound((item, hierarchyMember) =>
           {
                item.Text = hierarchyMember.Description;
                item.Value = hierarchyMember.HierarchyDefinitionId.ToString(); // - 1st column of Composite Key
                item.Value = hierarchyMember.EmployeeId.ToString(); //?? - 2nd column of Composite Key 
           })
        );
    })
    .Render();
}


The two *key* columns in my self-referencing table are HierarchyDefinitionId and EmployeeId (in the above I assign both of these fields to the "value" property - this is obviously not correct).  HierarchyMember1 (collection of HierarchyMember) is what the Entity Framework (4.1) labels the self-referencing constraint.

The controller referred to above gets the parents (there are three) - but that's all I see on the page - i.e. a tree (no expand icons) with three parents

Does anyone know how I can do (via the above leve
raging the self-referencing constraint, or via stored procedure/CTE, etc) ?

Many thanks
Travis

Tags
TreeView
Asked by
Travis
Top achievements
Rank 1
Share this question
or