This documentation is archived and is not being maintained.

TreeView.LevelStyles Property

Gets a collection of Style objects that represent the node styles at the individual levels of the tree.

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

public TreeNodeStyleCollection LevelStyles { get; }
/** @property */
public TreeNodeStyleCollection get_LevelStyles ()

public function get LevelStyles () : TreeNodeStyleCollection

Not applicable.

Property Value

A StyleCollection that represents the node styles at the individual levels of the tree.

Use the LevelStyles collection as an alternative to the individual style properties (such as the NodeStyle property) to control the style of nodes at the individual levels of the tree. The first style in the collection corresponds to the style of nodes in the first level of the tree. The second style in the collection corresponds to the style of nodes in the second level of the tree, and so on. This property is most often used to generate table of contents–style navigation menus where nodes at a certain level should have the same appearance, regardless of whether they have child nodes.

Style properties are applied in the following order:

  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 LevelStyles property to create a navigation menu. The control is always fully expanded, with the expansion node indicators and images hidden. Also, the ChildNodesPadding property is used to control the spacing of the node levels.

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

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

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

      <!-- Populate the LevelStyles collection of the TreeView control -->
      <!-- declaratively.                                              -->
      <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" />


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