This documentation is archived and is not being maintained.

TreeNodeBinding.SelectAction Property

Gets or sets the event or events to raise when a node to which the TreeNodeBinding object is applied is selected.

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

public TreeNodeSelectAction SelectAction { get; set; }

Property Value

Type: System.Web.UI.WebControls.TreeNodeSelectAction
One of the TreeNodeSelectAction values. The default is TreeNodeSelectAction.Select.

When the TreeView control is bound to a data source, use the SelectAction property to specify the value to bind to the SelectAction property of a TreeNode object. This binding relationship affects all TreeNode objects to which the TreeNodeBinding object is applied. The SelectAction property is used to specify which event or events are raised when a node is selected.

NoteNote

You can selectively override the SelectAction property by setting the SelectAction property of each node directly.

The following table lists the available options.

SelectAction value

Description

TreeNodeSelectAction.Expand

Toggles the node between expanded and collapsed. Raises the TreeNodeExpanded event or the TreeNodeCollapsed event, as appropriate.

TreeNodeSelectAction.None

Raises no events when a node is selected.

TreeNodeSelectAction.Select

Raises the SelectedNodeChanged event when a node is selected.

TreeNodeSelectAction.SelectExpand

Raises both the SelectedNodeChanged and TreeNodeExpanded events when a node is selected. Nodes are only expanded, never collapsed.

NoteNote

The HoverNodeStyle is not rendered for a node with its SelectAction property set to TreeNodeSelectAction.None.

The value of this property is stored in view state.

This section contains two code examples. The first code example demonstrates how to use the SelectAction property to specify which event is raised when a node is clicked. The second code example provides sample XML data for the first code example.

The following example demonstrates how to use the SelectAction property to specify which event is raised when a node is clicked. For this example to work correctly, you must copy the sample XML data, provided after this code example, to a file named Book.xml.



<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Node_Changed(Object sender, EventArgs e)
  {

    Message.Text = BookTreeView.SelectedNode.Text + " node selected.";

  }

  void Node_Expanded(Object sender, TreeNodeEventArgs e)
  {

    Message.Text = e.Node.Text + " node expanded.";

  }

  void Node_Collapsed(Object sender, TreeNodeEventArgs e)
  {

    Message.Text = "";

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBinding SelectAction Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeNodeBinding SelectAction Example</h3>

      <asp:TreeView id="BookTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        DataSourceID="BookXmlDataSource"
        EnableClientScript="false" 
        OnSelectedNodeChanged="Node_Changed"
        OnTreeNodeExpanded="Node_Expanded"
        OnTreeNodeCollapsed="Node_Collapsed"   
        runat="server">

        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            TextField="Title"
            SelectAction="Expand"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            TextField="Heading"
            SelectAction="Expand"/>
        </DataBindings>

      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>

      <br /><br />

      <asp:Label id="Message" runat="server"/>

    </form>
  </body>
</html>



The following code example provides sample XML data for the preceding code example.

<Book Title="Book Title">
    <Chapter Heading="Chapter 1">
        <Section Heading="Section 1">
        </Section>
        <Section Heading="Section 2">
        </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
        <Section Heading="Section 1">
        </Section>
    </Chapter>
    <Appendix Heading="Appendix A">
    </Appendix>
</Book>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: