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?