This is a migrated thread and some comments may be shown as answers.

Saving Values from On Demand TreeView to a Database

1 Answer 120 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andre
Top achievements
Rank 1
Andre asked on 06 Aug 2015, 09:23 PM

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?

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 10 Aug 2015, 08:15 AM
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
Tags
TreeView
Asked by
Andre
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or