Asynchronous delayed loading of Treeview in Asp.net

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.