This example shows how to dynamically load child nodes through a web service.
The path to the web service and the name of the service method are specified in the
WebServiceSettings' Path and Method properties.
You need to set the ExpandMode of the desired nodes to "WebService".
<telerik:RadTreeView ID="RadTreeView1" runat="server" Width="300px" OnClientNodePopulating="nodePopulating">
<WebServiceSettings Path="ProductCategories.asmx" Method="GetTreeViewCategories" />
<Nodes>
<telerik:RadTreeNode Text="Products" Value="1" ExpandMode="WebService">
</telerik:RadTreeNode>
...
</Nodes>
</telerik:RadTreeView>
Optionally, you can handle the
nodePopulating,
nodePopulated
and
nodePopulationFailed events.
You can use the LoadingStatusTemplate property to create a loading template.
To use the integrated support, the web service should have the following signature:
[ScriptService]
public class WebServiceName : WebService
{
[WebMethod]
public RadTreeNodeData[] WebServiceMethodName(RadTreeNodeData node, object context)
{
// We cannot use a dictionary as a parameter, because it is only supported by script services.
// The context object should be cast to a dictionary at runtime.
IDictionary<string, object> contextDictionary = (IDictionary<string, object>) context;
//...
}
}
The nodePopulating event can be used to pass parameters to the web service through the "context" dictionary.
function nodePopulating(sender, eventArgs)
{
var node = eventArgs.get_node();
var context = eventArgs.get_context();
context["CategoryID"] = node.get_value();
}