I was having A LOT of issues with this, and doing something restful, so i decided to create a workaround.
What I want to do, is that when the node expands, call a JS Function with the value of the clicked node. From there, i will fetch a query, return the result, and then use the builtin javascript to append nodes to the page.
I figure there is some way to go about this. I was thinking there was a “onNodeExpand” Attribute of the control which i could use to fire off the JS scripts.
THoughts?
The TreeView supports Load on Demand feature. Meaning the items of a node will be automatically downloaded from the server only when user expands a node. The server side code can be a custom logic to fill the child nodes which you are in control. Only setting you need to do is to let the tree view know what is the AJAX call it has to make.
Take a look at the following example:
http://demos.telerik.com/aspnet-mvc/treeview/ajaxloading
In this example we are binding to Northwind database and building a tree of emplyoyees. Here is the code to define the treeview and set the load on demand on the treeview:
In the above code, the TreeView has a DataBinding set to indicate that it needs to make a Ajax call to a action method named _AjaxLoading inside TreeViewController.
if at all you are looking for on demand loading based on custom logic this is the simplest way to achieve it.
You can bind the tree view from the client side too. The TreeView has an extensive client side eventing and client side API. I recommend you to go through the following demos:
http://demos.telerik.com/aspnet-mvc/treeview/clientsideevents – this list all the client side events supported
http://demos.telerik.com/aspnet-mvc/treeview/clientsideapi – this lists all the clent side API support for the treeview
Hope i was able to answer your question.
Lohith (Tech Evangelist, Telerik India)