Reputation: 21
I am binding a tree view to a model. I want to add a 'static' parent node. Is that possible?
Here is code I am using now.
@(Html.Telerik().TreeView()
.Name("secteurActivite")
.ShowCheckBox(true)
.ExpandAll(false)
.ShowLines(true)
.BindTo(Model.secteurActivites, mappings =>
{
mappings.For<SecteurActivite>(binding => binding
.ItemDataBound((item, secteur) =>
{
item.Text = secteur.Nom;
item.Value = secteur.SecteurActiviteId.ToString();
if (secteur.SecteurActiviteParentId != null)
{
item.ImageUrl = "~/Content/Images/document.bmp";
}
else
{
item.ImageUrl = "~/Content/Images/folder.bmp";
}
})
.Children(secteur => secteur.SecteurActivite1));
})
)
Upvotes: 2
Views: 448
Reputation: 3372
You could add a new class called Root...
public class Root {
public IEnumerable<SecteurActivite> SecteurActivites { get;set; }
}
Then, instead of the secteurActivites list on the model, make it a list of 1 Root object...
public IEnumerable<Root> SecteurActivites =
new List<Root> {
new Root { SecteurActivites = secteurActivites }
};
Then, add another mapping for Root:
mappings.For<Root>(binding => binding
.ItemDataBound((item, root) =>
{
item.ImageUrl = "~/Content/Images/folder.bmp";
})
.Children(root => root.SecteurActivites));
Hope this helps.
Upvotes: 1