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

[Solved] How to build a hierarchal Treeview using lambda expressions

1 Answer 33 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.
Michael
Top achievements
Rank 1
Michael asked on 15 Mar 2012, 01:33 PM
I have a collection of items which are hierarchally linked by parent id and would like to know how can I generate a treeview by using lambda. This is my code so far but it does not build a hierarchal tree:
@(Html.Telerik().TreeView()
                            .Name("ContentTree")
                            .BindTo(Model.ContentList, mappings =>
                            {
                                mappings.For<Content>(binding => binding
                                    .ItemDataBound((item, content) =>
                                    {
                                        item.Text = content.Name;
                                        item.ImageUrl = Url.Content("~/SiteContent/Images/Tree/folder.gif");
                                        item.Expanded = true;
                                    }));
                            })
                        )

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 16 Mar 2012, 09:44 AM
Hello Michael,

You need to specify how the children items are bound. See the binding to model online example. Since you are using parent IDs, you might have to build the hierarchy in the controller.

Kind regards,
Alex Gyoshev
the Telerik team
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
TreeView
Asked by
Michael
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or