Store a Node or a Tree in a File or Database

5 posts, 1 answers
  1. Christian Sommer
    Christian Sommer avatar
    19 posts
    Member since:
    Sep 2009

    Posted 25 Nov 2009 Link to this post


    sometime I'm creating trees based on  very complex and timeconsumpting database-queries.

    My question is, if it is possible to store the  tree (after first creation in a file or database,
    so it can be cached for other users.

    Second question is: how to set the tree from that cache (usually a binary-text)?

    Is there an easy way to do that?

    Best regards.
  2. Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 25 Nov 2009 Link to this post


    RadTreeView does not have this functionality, however this is easy to achieve.

    The tree supports binding to hierarchical data Binding to Hierarchical data. Given this, you would prepare a table:

    - TreeId //to support multiple different trees in the same table
    - Id
    - ParentId
    - NodeText
    - NodeValue

    The table would have the data that comes from your complex queries.

    Then you would only query this table given the TreeId and bind the data to the tree with the following settings:
    var list = new List<MySavedNodeObject>()
    //add nodes from database to the list

     treeView.DataTextField = "NodeText";
    treeView.DataValueField = "NodeValue";
    treeView.DataFieldID = "Id";
    treeView.DataFieldParentID = "ParentId";
    treeView.DataSource = list;

    Please refere to the link above how to achieve the required functionality.

  3. DevCraft R3 2016 release webinar banner
  4. Answer
    Peter avatar
    6637 posts

    Posted 26 Nov 2009 Link to this post

    Hi Christian,

    You can also consider using the GetXml() and LoadXmlString() methods of RadTreeView.

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Christian Sommer
    Christian Sommer avatar
    19 posts
    Member since:
    Sep 2009

    Posted 26 Nov 2009 Link to this post

    Hello Roland,

    Unfortunately I'm not able to create a simple structured table an then uns a web-service for dynamic load node per node,
    level by level.

    In my application very much is customizeable, (different styles, different contextmenus, some nodes are checkable, some are not, etc.)

    So, at the end of developing, It could be that I'll try to create a webservice which returns nodes - not node-data.
    ... and I'll attach it to the tree, by manipulationg the innerHTML.
    Well, in fact, we're just starting to develop with telerik tools, we'd like to youse default features more then to create our own work-arrounds.


    But Roland,
    your tip is not obsolete, because I could save the time consupting query results in a temp-table wich could be accessed much faster.

    First I'll try GetXml() and LoadXmlString() .

    Thanks a lot.

  6. Christian Sommer
    Christian Sommer avatar
    19 posts
    Member since:
    Sep 2009

    Posted 10 Dec 2009 Link to this post


    I've experienced some tests with the
    GetXml() and LoadXmlString() methods.

    They're working great, when you're able to store a complete tree.

    Now I need a little bit mor help:
    To improve cachinng, I want to cache my TreeRootNodes, which are created with theire own definitions.
    Differen users could see different RootNodes, so I can't cache the entire tree.

    In fact, TreeNodes don't have a GetXml() method, I've experienced with a litle work a round.
    I've create a second Treeview called "CacheTree". After creating so RootNode (with all its Subnodes)
    I'm storing this Node by its own in the CacheTree and store its XML with the GetXml() method.

    My problem now is to restore that XML back to the RootNode Object.

    1. Caching



    "CachingTime").Value = Now




    "CachedTree").Value = CacheTree.GetXml()




    2. Load Cached Value



    ---- Here's my Problem ----



    MasterNode = CacheTree.GetAllNodes
    Now MasterNode contains only the top-Level Node, all Subnodes are missing.



    What am I supposed to do?

Back to Top
DevCraft R3 2016 release webinar banner