Default TreeView

The Tree View is a control used to display hierarchical data in tree-like form. Each Tree View node is represented by a BootstrapTreeViewNode object and provides access to a collection of its sub-nodes through the Nodes collection property.

<dx:BootstrapTreeView runat="server">
    <Nodes>
        <dx:BootstrapTreeViewNode Text="Home" Expanded="true">
            <Nodes>
                <dx:BootstrapTreeViewNode Text="News">
                    <Nodes>
                        <dx:BootstrapTreeViewNode Text="For Developers">
                        </dx:BootstrapTreeViewNode>
                        <dx:BootstrapTreeViewNode Text="Website news">
                        </dx:BootstrapTreeViewNode>
                    </Nodes>
                </dx:BootstrapTreeViewNode>
                <dx:BootstrapTreeViewNode Text="Our Mission">
                </dx:BootstrapTreeViewNode>
            </Nodes>
        </dx:BootstrapTreeViewNode>
        ...
    </Nodes>
</dx:BootstrapTreeView>

Nodes Selection

The Tree View control supports selection of nodes with a mouse click. To allow node selection, set the control’s AllowSelectNodes property to true. Note that only one node can be selected at a time.

Handle the client ItemClick or server ItemClick event to detect a selection change. You can identify the clicked item by the value of its Name property.

Moreover, the Tree View control can automatically select an item for a current page. You can control this behavior using the SyncSelectionMode property.

<dx:BootstrapTreeView runat="server" AllowSelectNode="true">
    <Nodes>
        ...
    </Nodes>
</dx:BootstrapTreeView>

Load Nodes on Callbacks

The Tree View control can obtain its node from the server as needed using callbacks. When this mode is activated, the contents of collapsed nodes are not present on the client until these nodes are expanded. To specify whether to use the callback technology to transfer node data to from server, use the EnableCallBacks property.

Note that in this demo the callback time is intentionally extended so that the loading indicator is visible during callbacks.

<dx:BootstrapTreeView runat="server" EnableCallBacks="true">
    <Nodes>
        ...
    </Nodes>
</dx:BootstrapTreeView>

Hide Expand Buttons

You can control whether to display the Tree View’s Hide (-) and Expand (+) buttons using the ShowExpandButtons property.

Collapsing and expanding actions will remain available for end-users via a mouse double click. To prevent these actions, subscribe to the client-side ExpandedChanging event and set e.cancel to the true value in your event handler.

<dx:BootstrapTreeView runat="server" ShowExpandButtons="false">
    <Nodes>
        ...
    </Nodes>
</dx:BootstrapTreeView>

Badges

The TreeView can display supplementary information for any node within a badge. A badge can display a text, an icon or both. Use the following API to configure badges on the server side:

The methods listed below allow you to manipulate badges on the client:

Note that the BootstrapTreeViewNode.Badge property does not affect templated nodes.

<dx:BootstrapTreeView runat="server" ShowExpandButtons="false">
    <Nodes>
        <dx:BootstrapTreeViewNode Text="Inbox" Expanded="true">
            <Badge Text="10" />
            <Nodes>
                <dx:BootstrapTreeViewNode Text="Work">
                    <Badge Text="8" />
                </dx:BootstrapTreeViewNode>
                <dx:BootstrapTreeViewNode Text="Personal" />
                <dx:BootstrapTreeViewNode Text="Other">
                    <Badge Text="2" />
                </dx:BootstrapTreeViewNode>
            </Nodes>
        </dx:BootstrapTreeViewNode>
        <dx:BootstrapTreeViewNode Text="Sent Items" />
        <dx:BootstrapTreeViewNode Text="Drafts">
            <Badge Text="1" />
        </dx:BootstrapTreeViewNode>
        <dx:BootstrapTreeViewNode Text="Spam">
            <Badge Text="3" />
        </dx:BootstrapTreeViewNode>
    </Nodes>
    <ClientSideEvents NodeClick="onNodeWithBadgeClick" />
</dx:BootstrapTreeView>

Auto PostBack

The Auto Postback feature allows the TreeView control to automatically initiate a postback when an end-user clicks or expands/collapses a node. Set the AutoPostBack property to true to enable this feature.

Use the NodeClick event to process the node click on the server side. Also, you can process the expand/collapse actions on the server side via the ExpandedChanging and ExpandedChanged events.

<dx:BootstrapTreeView ID="TreeViewAutoPostBack" runat="server" AutoPostBack="true" OnNodeClick="TreeViewAutoPostBack_NodeClick">
    <Nodes>
        ...
    </Nodes>
</dx:BootstrapTreeView>

Data Binding

The Tree View control supports binding to a data source, which can be any object that implements the IHierarchicalEnumerable or IHierarchicalDataSource interface (e.g., SiteMapDataSource, XmlDataSource, etc.). Set the DataSourceID property to assign a data source to a Tree View.

A data-bound Tree View automatically creates a node for each data item. A created node obtains values for its properties from data item attributes with matching names. You can also explicitly specify mappings between node properties and names of data item attributes using the following properties.

  • IconCssClassField - Specifies the name of a data field providing CSS classes of icons displayed by Tree View nodes.
  • NameField - Specifies the name of a data field providing unique identifiers to nodes.
  • NavigateUrlField - Specifies the name of a data field providing node navigation locations.
  • TextField - Specifies the name of a data field providing node display texts.
  • ToolTipField - Specifies the name of a data field providing node tooltip texts.

You can modify settings of each auto-created Node object during data binding in the NodeDataBound event.

Virtual Mode

When the Tree View control is functioning in Virtual mode, child nodes are created and initialized only when their parent node is expanded. To activate the Virtual mode, handle the Tree View’s VirtualModeCreateChildren event, which occurs when expanding a parent node for the first time. In the event handler, programmatically create a list of BootstrapTreeViewVirtualNode objects representing child nodes for the currently expanded node. For each created node that has no children, set the IsLeaf property to true so that the node does not display the expand button.

Note that in this demo the callback time is intentionally extended so that the loading indicator is visible during callbacks.

<dx:BootstrapTreeView ID="TreeViewVirtual" runat="server" EnableCallBacks="true" OnVirtualModeCreateChildren="treeView_VirtualModeCreateChildren">
</dx:BootstrapTreeView>

Templates

The Tree View control supports templates allowing you to customize control appearance and layout. You can define templates for a node’s text or the entire node content. A template can be applied to all nodes (using control level templates) or a specific node (using node level templates). Use the following properties to specify templates.

BootstrapTreeView properties:

  • NodeTemplate – Specifies a common template used for displaying all nodes' content in the current tree view control.
  • NodeTextTemplate – Specifies a common template used for displaying all nodes' text content in the current tree view control.

BootstrapTreeViewNode properties:

  • Template – Specifies a template used for displaying the current node's content.
  • TextTemplate – Specifies a template used for displaying the current node's text content.
<dx:BootstrapTreeView runat="server">
    <NodeTextTemplate>
        <div class="media">
            <div class="media-left">
                <span class="fa fa-circle"></span>
            </div>
            <div class="media-body media-middle">
                <h4 class="media-heading"><%# Container.Node.Text %></h4>
                <p>
                    DevExpress <%# Container.Node.Text + " " + (Container.Node.Parent.Name == "UIControls"
                        ? (Container.Node.Name == "MVC" ? "Extensions" : "Controls and Libraries")
                        : "") %> for the .NET Framework.
                </p>
            </div>
        </div>
    </NodeTextTemplate>
    <Nodes>
        <dx:BootstrapTreeViewNode Name="UIControls" Text=".NET Controls" Expanded="true">
            <TextTemplate>
                <h3><%# Eval("Text") %></h3>
            </TextTemplate>
            <Nodes>
                ...
            </Nodes>
        </dx:BootstrapTreeViewNode>
        <dx:BootstrapTreeViewNode Name="CrossPlatform" Text="Cross Platform">
            <TextTemplate>
                <h3><%# Eval("Text") %></h3>
            </TextTemplate>
            <Nodes>
                ...
            </Nodes>
        </dx:BootstrapTreeViewNode>
    </Nodes>
</dx:BootstrapTreeView>

Client-Side Events

This demo illustrates the capabilities of the Tree View control's client events and allows you to specify which client-side events you want to track. Interact with the Tree View interface to see the information about all tracked events raised in response to your actions in the event log.

The node.name property of the event handler's parameter allows you to identify the node for which an event has been raised.

  • NodeClick – Fires when an end-user clicks a TreeView node.
  • ExpandedChanging – Fires before the expansion state of a node is changed. Allows to cancel this operation or force processing the event on the server side.
  • ExpandedChanged – Fires after the expansion state of a node is changed.
Trace Events:
<dx:BootstrapTreeView runat="server">
    <ClientSideEvents
        Init="onInit"
        NodeClick="onNodeClick"
        ExpandedChanging="onExpandedChanging"
        ExpandedChanged="onExpandedChanged" />
    <Nodes>
        ...
    </Nodes>
</dx:BootstrapTreeView>

Client-Side Functionality

The Tree View control offers an advanced client-side API allowing you to manipulate the control and its elements.

The EnableClientSideAPI property specifies whether or not the client-side API is available. Note that the client-side API is automatically enabled if the ClientInstanceName property is specified or any client-side event available through the ClientSideEvents property is handled.

This demo allows you to interactively explore capabilities of the Tree View control's client-side API.

BootstrapClientTreeView methods:

BootstrapClientTreeViewNode methods:

<dx:BootstrapTreeView ClientInstanceName="treeView" AllowSelectNode="true" runat="server">
    <Nodes>
        ...
    </Nodes>
</dx:BootstrapTreeView>
Screen Size
Color Themes
Demo QR Code