This documentation is archived and is not being maintained.

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 Value

Type: System.Web.UI.WebControls.TreeNodeStyle
A TreeNodeStyle that represents the style of the selected node in the TreeView control. The default is null, 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 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