As the title suggests, I am binding a WebDataTree to an IEnumerable list at runtime. The IEnumerable has a list property (also an IEnumerable) and so on, which the WebDataTree picks up fine. However, the names of all nodes are represented as the fully qualified name of the class (e.g. Phoenix.DataNodes.ClienNode).
How can I tell the WebDataTree to bind to a specific property in the IEnumerable so that the text displayed is the underlying value of that property?
I seem to have resolved the first issue by applying a template to each node on the NodeBound event. However, I now have a new issue. After a postback, every node loses the previously bound DataItem.
Keeping in mind that I'm binding the data programmatically (as these are IEnumerable's and not datasets as all the examples seem to use), how can I ensure that all the nodes in the tree persist their DataItems after a postback, or alternatively, how can I create a binding source in the ASPX page that creates the children from an IEnumerable property in the parent?
Thanks,
Alex
Hello Alex,
Thank you for writing in our community.
I have created a basic sample for you to show you how to bind the WebDataTree to IEnumerable. Please take a look at it and let me know is that what are you trying to accomplish. Also, can you please provide me more information on your case scenario or send me a working sample so I can better assist you. Additionally here are some resources that you might find useful:
Hello,
Thank you for the clarifications. By data becoming undound you mean it's not available on consecutive events after the initial page render, correct? That is completely normal as page lifecycle has already completed for the initial request, see here:
https://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx
https://msdn.microsoft.com/en-us/library/aa719775(v=vs.71).aspx
Which means the objects have been disposed (controls and data included). While the ASPX markup will re-initialize the WebDataTree control on the Page once postback occurs, if you assign data source in code, it will need to be assigned again. I think you will agree with me that transferring all data back and forth via viewstate is an extreme measure as well. However, note that if you use async postbacks the page and controls will not be rendered (as that is the whole point of ajax) and re-binding should only happen if it is required which is left entirely to the developer to decide.
The event arguments carry information for the selected node that is always available, while tree collections and related (active item) will require databind:
protected void WebDataTree1_NodeClick(object sender, DataTreeNodeClickEventArgs e)
{
//Always present properties:
string value = e.Node.Value;
string text = e.Node.Text;
int level = e.Node.Level;
int index = e.Node.Index;
// Requires data binding:
object item = (sender as WebDataTree).ActiveNode.DataItem;
}
So the choice is really up to you – if the info in the node is not enough to decide your application's reaction and you need access to the data items then you can freely query your data without binding the tree.
If the data retrieval is the bottleneck, then it should probably be cached on the server side as that is the entire point of data binding – controls are data-bound not data-containing/caching.
I hope that is helpful and do let me know if you if there's anything else we can help with on this matter.
Regards,
Damyan Petev
Associate Software Developer
Infragistics, Inc.
Just to re-iterate, rebinding after every postback is a non-option, as it increases the load time from a split second to 5 or so seconds (the example given rebinds after every click).
Hi there,
I should have been more clear, using our own structures the data becomes unbound. Our data has one IEnumerable structure (A ClientList) with an IEnumerable property called FundList (which points to the IEnumerable structure FundList). FundList has both a product and option list as properties also, so there are 3 levels.
On the first databind, I can see all nodes have the correct DataItem represented, and the correct structure is shown. However, as soon as I click on another node, upon stepping through the event, I can see that the ActiveNode's dataitem property is null, as is all other nodes.
Rebinding on every load isn't really an option, as we have around 80 clients, some with up to 10 funds, with up to 20 products and options in each of those funds (so it takes a bit to load).
Any ideas?
Hi Alex,
I hooked to this event but the bound data stays there as expected.
Can you please let me know if there are any changes that you made to Marina's sample?
Thanks for the reply.
I've given your example a shot, but the underlying objects seem to lose their binding on a postback (even if it's asynchronous). Any ideas?
I can see that on the initial bind the objects are there, but as soon as a click a node and the OnNodeClicked event is fired, all the objects tied to each node's DataItem property are lost.