An old question. But, since this kept showing in search results when I too was researching the issue you describe, I thought I would post a solution for others that may come across this.
When doing TreeView control on a web page that uses PopulateOnDemand, You basically want to start here:
[
^]
For the checkboxes, however, if you want all the child nodes to be checked when the parent node is checked, you're going to need JavaScript. For that, I found this to work well:
c# - Treeview in web form check child nodes on parent node check - Stack Overflow[
^]
The only piece missing from that, is the situation you describe. For example, if a node has not yet been expanded, and therefore populated, then there are no checkboxes yet to be checked. So if the parent node is checked when the node is expanded, none of the children will be checked.
The fix for that, as it turns out, is simple. In the routine that adds a child node, and directly before adding the child node, then include the following:
if (node.Checked) {
newNode.Checked = true;
}