This documentation is archived and is not being maintained.

TreeView::TreeNodePopulate Event

Occurs when a node with its PopulateOnDemand property set to true is expanded in the TreeView control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public:
 event TreeNodeEventHandler^ TreeNodePopulate {
	void add (TreeNodeEventHandler^ value);
	void remove (TreeNodeEventHandler^ value);
}
<asp:TreeView OnTreeNodePopulate="TreeNodeEventHandler" />

Sometimes, it is not practical to statically predefine the tree structure due to data size or custom content that depends on user input. Because of this, the TreeView control supports dynamic node population. When the PopulateOnDemand property for a node is set to true, that node gets populated at run time when the node is expanded.

To populate a node dynamically, first set the PopulateOnDemand property for the node to true. Next, define an event-handling method for the TreeNodePopulate event that populates the node programmatically. A typical event-handling method retrieves node data from a data source, places the data into a node structure, and then adds the node structure to the ChildNodes collection of the node being populated. A node structure is created by adding TreeNode objects to the ChildNodes collection of a parent node.

NoteNote:

When the PopulateOnDemand property for a node is set to true, the node must be populated dynamically. You cannot declaratively nest another node below it; otherwise, an error will occur on the page.

Supported browsers (Microsoft Internet Explorer 4.0-compatible browsers and later) can also take advantage of client-side node population. When enabled, this allows the TreeView control to populate a node dynamically on the client when that node is expanded, which prevents the need to post back to the server. For more information on client-side node population, see PopulateNodesFromClient.

For more information about handling events, see Consuming Events.

The following code example demonstrates how to use the TreeNodePopulate event to populate the nodes in the TreeView control dynamically on the server. Notice that the EnableClientScript property is set to false to prevent expanding-node events from being handled on the client.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: