TreeView.SelectedNodeStyle Property

Gets the TreeNodeStyle object that controls the appearance of the selected node in the TreeView control.

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

public TreeNodeStyle SelectedNodeStyle { get; }
/** @property */
public TreeNodeStyle get_SelectedNodeStyle ()

public function get SelectedNodeStyle () : TreeNodeStyle

Not applicable.

Property Value

A TreeNodeStyle that represents the style of the selected node in the TreeView control. The default is a null reference (Nothing in Visual Basic), which indicates that the SelectedNodeStyle property is not set.

Use the SelectedNodeStyle property to control the appearance of the selected node in the TreeView control. This property is read-only; however, you can set the properties of the TreeNodeStyle object it returns. The properties can be set declaratively in the form Property-Subproperty, where Subproperty is a property of the TreeNodeStyle object (for example, SelectedNodeStyle-ForeColor). The properties can also be set programmatically in the form Property.Subproperty (for example, SelectedNodeStyle.ForeColor). Common settings usually include a custom background color, foreground color, font properties, and node spacing. Style properties are applied in the following order of precedence:

  1. NodeStyle.

  2. RootNodeStyle, ParentNodeStyle, or LeafNodeStyle, depending on the node type. If the LevelStyles collection is defined, it is applied at this time, overriding the other node style properties.

  3. SelectedNodeStyle.

  4. HoverNodeStyle.

The following code example demonstrates how to use the SelectedNodeStyle property to control the appearance of the selected node in the TreeView control.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

    void Select_Change(Object sender, EventArgs e)

        Message.Text = "You selected: " + LinksTreeView.SelectedNode.Text;



<html xmlns="" >

    <head runat="server">
    <title>TreeView SelectedNodeStyle Example</title>
        <form id="form1" runat="server">
            <h3>TreeView SelectedNodeStyle Example</h3>

            <asp:TreeView id="LinksTreeView"
                Font-Names= "Arial"
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                    <asp:TreeNodeStyle ChildNodesPadding="5" 
                    <asp:TreeNodeStyle ChildNodesPadding="5" 
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                    <asp:TreeNode Text="Table of Contents"
                        <asp:TreeNode Text="Chapter One">
                            <asp:TreeNode Text="Section 1.0">
                                <asp:TreeNode Text="Topic 1.0.1"/>
                                <asp:TreeNode Text="Topic 1.0.2"/>
                                <asp:TreeNode Text="Topic 1.0.3"/>
                            <asp:TreeNode Text="Section 1.1">
                                <asp:TreeNode Text="Topic 1.1.1"/>
                                <asp:TreeNode Text="Topic 1.1.2"/>
                                <asp:TreeNode Text="Topic 1.1.3"/>
                                <asp:TreeNode Text="Topic 1.1.4"/>
                        <asp:TreeNode Text="Chapter Two">
                            <asp:TreeNode Text="Section 2.0">
                                <asp:TreeNode Text="Topic 2.0.1"/>
                                <asp:TreeNode Text="Topic 2.0.2"/>
                    <asp:TreeNode Text="Appendix A" />
                    <asp:TreeNode Text="Appendix B" />
                    <asp:TreeNode Text="Appendix C" />
            <br /><br />
            <asp:Label id="Message" runat="server"/>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0