When using the Treeview Server Control, the static definition of the data structure is sometimes not feasible, or the data may depend on the information collected during the runtime. To dynamically display data,TreeviewControls Support Dynamic node filling. SetTreeviewWhen the control is configured to be filled, the control triggers an event when the user expands the node. Event ProcessingProgramSearch the corresponding data and fill it with the node you clicked. To fill in dataTreenodeObject. Set the populateondemand attribute of the nodeTrueAnd create a treenodepopulate event handlerTreenodeObject. (Derived from M $ DN)
Example:
<Asp: Treeview id = "trvtreemenu" runat = "server" autogeneratedatabindings = "false" expanddepth = "0" populateondemand = "true" showexpandcollapse = "true"
Width = "195px"Ontreenodepopulate = "treeviewappstreenodepopulate"Expandimageurl = "img/selectchildnode.gif" font-names = "" font-size = "10pt" Height = "100%" showlines = "true" forecolor = "black">
<Nodes>
<Asp: treenode value = "1" text = "Root Node"Populateondemand = "true"Navigateurl = "#"> </ASP: treenode>
</Nodes>
</ASP: Treeview>
At the backendCodeYou can implement the treeviewinclutreenodepopulate method to dynamically fill the treenode node.
Public void treeviewinclutreenodepopulate (Object sender, treenodeeventargs E)
{
If (iscallback)
If (E. node. childnodes. Count = 0)
{
Loadchildnode (E. node );
}
}
However, you will find that because the node is dynamically filled, the entire Treeview is always in the shrinking State when the page is just opened, whether or not you have set
Showexpandcollapse, you will also find that the treeviewmediatreenodepopulate function will be triggered only by clicking the mouse to expand the tree.
In this way, you want to make the tree partially expand after the page is loaded, and you want to usePopulateondemandOnly manually attach nodes to be expanded.Populateondemand = "true"Method
The original code is slightly modified.
<Asp: Treeview id = "trvtreemenu" runat = "server" autogeneratedatabindings = "false" expanddepth = "0" populateondemand = "true" showexpandcollapse = "true"
Width = "195px"Ontreenodepopulate = "treeviewappstreenodepopulate"Expandimageurl = "img/selectchildnode.gif" font-names = "" font-size = "10pt" Height = "100%" showlines = "true" forecolor = "black">
<Nodes>
<Asp: treenode value = "1" text = "Root Node"Populateondemand = "false"Navigateurl = "#"> </ASP: treenode>
</Nodes>
</ASP: Treeview>
Add
Loadchildnode (trvtreemenu. nodes [0 ]);
When a node is added to loadchildnode, subsequent nodes are opened as needed:
Child. populateondemand = true;
Summary:
In the Treeview control, when populateondemand is used for on-demand loading, subnodes cannot exist under it, that is, initialization cannot be performed manually. To manually initialize populateondemand, set it to false.