The problem here is the following:
- The nodes are templated in a wrong way!
Currently your nodes are being templated once (on initial load of the page), while they should be templated on every postback too.
The way to implement this would be:
1. move the implementation of Page_Load handler in Page_Init time;
2. add ParentId to your data source and create the nodes only through databinding;
3. in Page_Init handler rebind the tree only if it's not postback;
4. in the dataSource add a value column (nullable), and assign value which should indicate if the node should be templated or not;
5. in Page_Init handler iterate through the nodes of the treeView (GetAllNodes would do the job to get all nodes in array and iterate through them) checking the value of the nodes, and by some criteria determining whether this node should be templated or not, and if it should be, then add the control in it's controls collection;
6. when you try to get reference to the control inside the controls collection of a node, please, do it this way:
Also after you get this to work, you probably will have to use a better style of templating - implementing ITemplate interface that we provide. Here is a nice little article on that: http://www.telerik.com/help/aspnet-ajax/tree_templatesruntime.html
I recommend that you use this way of templating (it even shows some of the above mentioned measures that you need to take, like moving templateing in Page_Init time and so on).
- If you upgrade your controls, you can make use of the newly introduced event TemplateNeeded, not just over RadTreeView, but also over RadPanelBar, RadListBox, RadToolBar and on many others of the rest of the RadControls package.
Please, try to implement the suggested and if you experience some problems during this process, don't hesitate to write to us again!
Hope this is helpful for you!
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Telerik Public Issue Tracking
system and vote to affect the priority of the items