Saving Values from On Demand TreeView to a Database

2 posts, 0 answers
  1. Andre
    Andre avatar
    4 posts
    Member since:
    Oct 2013

    Posted 06 Aug 2015 Link to this post

    We have a TreeView control that needs to load a lot of data, so we use on-demand mode.  We also require each node have a checkbox and save what the user checked in a database.  We can load the TreeView just fine.  The problem comes when saving.  Sometimes, not all the values from all the nodes are saved.  After doing some experimenting, I came determined the cause but cannot think of a simple solution.

     Here's the scenario to illustrate:

    You come to a page with the TreeView control for the first time, expand a tree branch, say branch called "website1" and check the nodes under website1 that say "Homepage" and "Contact Us".  Then you click save and leave the page.  The database saves "Homepage" and "Contact Us" as expected.  Now you come back to the page, expand the node "website2" and check something there and click save.  The problem is the "Homepage" and "Contact Us" you selected from website1 the first time are no longer saved in the database as you did not expand the website1 branch.

    When saving, we delete all previous values selected in the database and loop through the CheckedNodes collection to determine which nodes the user checked.  However, because you did not expand the website1 branch the second time, the TreeView will not have the 2 nodes checked due to on-demand mode.

     Does anyone have any ideas on what to do?

  2. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 10 Aug 2015 Link to this post

    Hello,

    The scenario is quite custom indeed and the unusual behavior seems to be connected to the way the checked nodes are saved rather than to RadTreeView itself. One possible way to handle such scenario is to save the checked state per node in the datasource and pass it with a custom attribute. Then when you need to get all the checked nodes even when not all nodes are loaded you will have to traverse the datasource and get them manually.

    Regards,
    Plamen
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top