How to apply styles to the TreeView node types in ASP.NET

You can control individually the styles for different types of the TreeView nodes – root nodes, nodes that contain other nodes, selected nodes, etc. You use the TreeView.NodeStyle property to apply node style settings to all the nodes of the tree. The next table lists more specific styles you can use to isolate individual regions of the TreeView:






NodeStyle Applies to all nodes.
RootNodeStyle Applies only to the first-level (root) node.
ParentNodeStyle Applies to any node that contains other nodes, except root nodes.
LeafNodeStyle Applies to any node that doesn’t contain child nodes and isn’t a root node.
SelectedNodeStyle Applies to the currently selected node.

Applies to the node the user is hovering over with the mouse. These settings are applied only in up-level clients that support the necessary dynamic script.



Styles are listed in this table in order of most general to most specific. That means the SelectedNodeStyle style settings override any conflicting settings in a RootNodeStyle.  However, the RootNodeStyle, ParentNodeStyle, and LeafNodeStyle settings never conflict, because the definitions for root, parent, and leaf nodes are mutually exclusive. You can’t have a node that is simultaneously a parent and a root node, for example—the TreeView simply designates this as a root node.