When using the Treeview control, if the data volume is too large, the loading of the Treeview control will be slow, sometimes even failed,
To better use the Treeview control to load a large amount of data, it uses asynchronous latency to load the Treeview.
There is a "+" sign in front of each node in the Treeview. The event triggered by clicking this "+" is ontreenodeexpanded = "treeviewinclutreenodeexpanded". When loading the Treeview, if
If there are also subnodes, load only one subnode. When you click "+" to trigger the ontreenodeexpanded event, load
All the sub-nodes are fast.
1. The Treeview code displayed on the front-end is as follows:
<Asp: treeview id = "treeview1" runat = "server" font-size = "medium" ontreenodeexpanded = "inherit" forecolor = "lightslategray" leafnodestyle-forecolor = "# 333333ff" showlines = "true "expanddepth =" 1 "> <br/> <selectednodestyle cssclass =" selectnode "/> <br/> </ASP: treeview>
Note: You can use selectnode to control the background color of the selected node.
2. The code for the treenodeexpanded event in the background is as follows:
Protected void treeviewinclutreenodeexpanded (Object sender, treenodeeventargs e) <br/>{< br/> // only displays the child nodes of the current node, other closed nodes <br/> treenodecollection TNC = NULL; <br/> If (E. node. parent = NULL) <br/>{< br/> TNC = (Treeview) sender ). nodes; <br/>}< br/> else <br/> TNC = E. node. parent. childnodes; <br/> foreach (treenode node1 in TNC) <br/>{< br/> If (node1! = E. node) <br/>{< br/> node1.collapse (); <br/>}< br/> treenode node = (treenode) E. node; <br/> // Where tempnodeinfo includes node Information <br/> string tempnodeinfo = node. value; <br/> If (! Tempnodeinfo. startswith ("-1") <br/>{< br/> // Delete the last bound node Information <br/> node. childnodes. clear (); <br/> string [] tempnodeflag = tempnodeinfo. split (','); <br/> If (tempnodeflag [2]. tostring (). equals ("Area Code") <br/>{< br/> populatetreeviewfromfloorname ("1", node, convert. toint32 (tempnodeflag [4]), "1"); <br/>}< br/> else if (tempnodeflag [2]. tostring (). trim (). equals ("building number") <br/>{< br/> populatetreeviewfromunit ("2", node, convert. toint32 (tempnodeflag [4]), convert. toint32 (tempnodeflag [5]), "1"); <br/>}< br/> else if (tempnodeflag [2]. tostring (). trim (). equals ("unit number") <br/>{< br/> populatetreeviewfromroomusertree ("3", node, convert. toint32 (tempnodeflag [4]), convert. toint32 (tempnodeflag [5]), convert. toint32 (tempnodeflag [6]), "1"); <br/>}< br/>}
Note: populatetreeviewfromfloorname, populatetreeviewfromunit,
The fourth parameter "1" of populatetreeviewfromroomusertree is triggered by the treeviewappstreenodeexpanded event.
According to this flag delay loading.
The asynchronous delayed loading can be achieved through this approach.