Bind a IHierarchicalEnumerable to a treeview, and specify custom Images and navigation Urls
-
03-07-2019 - |
Question
I have an external datasource that implements IHierarchicalEnumerable. I'm trying to use that datasource for my TreeView, but I can't find a way to specify the images and individual navigation urls the control should render (there is some business logic there).
The examples I have seen all assume the Url and the Name and Image fields are directly available in the datasource but this is not the case here.
I tried to create an other datasource as a proxy implementing these properties, but this proves to be much harder than expected (due to GetHierarchyData().GetChildren()) so I hope there is an other way.
Thanks for the help!
Solution
You should take a look at the TreeNodeDataBound event of the TreeView control. In the event handler you can alter node properties (like image url or text) based on certain conditions.