ASP. NET-TreeView Web Server Control event

Source: Internet
Author: User

The TreeView Web Server Control provides several events that can be programmed. This allows you to run custom routines when an event occurs.

 

I. Events

A TreeView control event is triggered only when the user interacts with the control through some operations (such as selecting, expanding, or folding nodes. If you call the selection, expansion, or collapse method programmatically, these events are not triggered. For example, if you call the Expand method, no event is triggered.

 

The following table describes the events supported by the TreeView control.

Event
Description

TreeNodeCheckChanged
This occurs when the check box of the TreeView control is sent to the server for status change. Each TreeNode object changes once.

SelectedNodeChanged
This occurs when a node is selected in the TreeView control.

TreeNodeExpanded
It occurs when a node is expanded in the TreeView control.

TreeNodeCollapsed
A node is collapsed in the TreeView control.

TreeNodePopulate
This operation occurs when a PopulateOnDemand attribute is set to true in the TreeView control.

TreeNodeDataBound
It occurs when a data item is bound to a node in the TreeView control.

 


Ii. Example

2.1 SelectedNodeChanged event

The following code example demonstrates how to handle the SelectedNodeChanged event and how to access the SelectedNode attribute that raises the event. In this example, set the text of MyLabel To The ToolTip attribute text of SelectedNode.

PRotected void TreeView1_SelectedNodeChanged (object sender, EventArgs e)

{

MyLabel. Text = TreeView1.SelectedNode. ToolTip;

}

 

2.2. TreeNodeExpanded event and TreeNodeCollapsed event

The following code example demonstrates how to handle the TreeNodeCollapsed event and TreeNodeExpanded event, and how to access the collapsed or expanded TreeNode object.

Protected void treeviewinclutreenodecollapsed (object sender, TreeNodeEventArgs e)

{

MyLabel. Text = "You collapsed the" + e. Node. Value + "node .";

}

Protected void treeviewinclutreenodeexpanded (object sender, TreeNodeEventArgs e)

{

MyLabel. Text = "You expanded the" + e. Node. Value + "node .";

}

 

2.3 TreeNodePopulate event

The following code example demonstrates how to handle the TreeNodePopulate event and how to programmatically Add a new TreeNode object to the ChildNodes collection of nodes that raise the event.

Protected void treeviewinclutreenodepopulate (object sender, TreeNodeEventArgs e)

{

E. Node. ChildNodes. Add (new TreeNode ("New Node Populated on Demand "));

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.