Treeview with an IHierarchicalDataSource

5 posts, 1 answers
  1. Hans
    Hans avatar
    3 posts
    Member since:
    Jun 2008

    Posted 24 Nov 2008 Link to this post

    Hello

    I've been playing around with the RadTreeView control to bind it to custom business objects using a custom implemented IHierarchicalDataSource. I have found a sample data source control in the Telerik forums that shows the directory/file structure of the website (forum article: http://www.telerik.com/community/forums/aspnet/treeview/treeview-binding-to-business-object.aspx#274329; sample code: http://msdn.microsoft.com/en-us/library/system.web.ui.hierarchicaldatasourcecontrol.aspx).


    The issue I'm having is to implement a true 'load on demand' with the RadTreeView. If I use the sample code for the HierarchicalDataSource provided by Microsoft using the standard ASP.NET Treeview control, the 'load on demand' occurs appropriate: only when child nodes are required from a client-expand, the child-nodes are actually loaded on the server (you can check this by e.g. setting a break-point in the 'Select' method of the 'FileSystemDataSourceView'.

    The code I'm using for this:

     

    <demo:FileSystemDataSource ID="FileSystemDataSource1" runat="server"></demo:FileSystemDataSource>
    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="FileSystemDataSource1" ExpandDepth="0"></asp:TreeView>
    Please note that the ExpandDepth must be set to '0' and not 'FullyExpand': I only want to load the nodes that the user requests, because in my case there can be hundreds, even thousands of nodes.


    Now, when I change the ASP.NET Treeview into a RadTreeView, all childs are loaded with all children (so, recursive which returns the full hierarchical structure) on the first hit to the page (as if a FullyExpand is required). You can check this by setting a break-point in the GetChildren method of the 'FileSystemHierarchyData'. 

    The code used for this approach:

     

    <demo:FileSystemDataSource ID="FileSystemDataSource1" runat="server"></demo:FileSystemDataSource
    <telerik:RadTreeView ID="RadTreeView1" Runat="server" DataSourceID="FileSystemDataSource1"></telerik:RadTreeView>

     



    Using a structure as shown below is a real performance killer, which isn't the case when using the standard ASP.NET Treeview control:
    Top_1
        Level 1_1
            Level 1_1_1
            Level 1_1_2
            ...
            Level 1_1_50
        Level 1_2
            Level 1_2_1
            Level 1_2_2
            ...
            Level 1_2_50
        ...
        Level 1_50
            Level 1_50_1
            Level 1_50_2
            ...
            Level 1_50_50
    Top_2
        Level 2_1
        ....
            Level 2_50_50


    I've tried to change the properties of the RadTreeView to modify this behavior, but with no success.
    Am I missing something here? Any suggestions?

    As a side-question: can the RadTreeView handle in a proper manner lets say a thousand child nodes for one given parent?

    Thanks
    Hans

  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 25 Nov 2008 Link to this post

    Hi Hans,

    RadTreeView does not support this feature at the time being - when binding to hierarchical datasource all nodes are populated instantly. If you need load on demand you should subscribe to the NodeExpand event as demonstrated in this online example.

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Hans
    Hans avatar
    3 posts
    Member since:
    Jun 2008

    Posted 25 Nov 2008 Link to this post

    Albert,

    Thanks for the quick reply, it is highly appreciated!

    Just to make sure: are there other solutions to get this ‘true’ load-on-demand beside connecting to the NodeExpand method?

    Kind regards,
    Hans  

  4. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 25 Nov 2008 Link to this post

    Hello Hans,

    RadTreeView supports load on demand via setting the ExpandMode property of the node. Then you need to either use web service load on demand or subscribe to the NodeExpand event.

    The closest thing we have right now is using a binding so the nodes are rendered on demand on expanding. The databinding will be still complete though - only nodes which are expanded will be rendered. Here is an example with the XmlDataSource:

        <telerik:RadTreeView runat="Server" ID="RadTreeView1" CheckBoxes="True" CheckChildNodes="True" DataSourceID="XmlDataSource1" DataTextField="Text">
            <DataBindings>
                <telerik:RadTreeNodeBinding ExpandMode="ServerSideCallBack" Depth="0" />
            </DataBindings>
        </telerik:RadTreeView>
           
            <asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="/Nodes/Node">
                <Data>
                    <Nodes>
                        <Node Text="Root">
                            <Node Text="Child"></Node>
                        </Node>
                    </Nodes>
                </Data>
            </asp:XmlDataSource>

    I hope this helps,
    Atanas Korchev,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Hans
    Hans avatar
    3 posts
    Member since:
    Jun 2008

    Posted 26 Nov 2008 Link to this post

    Hi Albert,

    Again, thanks for the reply.

    The web service approach is definitly the one I need and, with only a littble more work,  solves the issue.

    Thanks for the pointing me to the solution
    Hans
Back to Top