Skip to main content
A newer version of this page is available. .

ASPxClientTreeList.GetNodeState(nodeKey) Method

Returns the specified node’s state.

Declaration

GetNodeState(
    nodeKey: string
): string

Parameters

Name Type Description
nodeKey string

A String value that identifies the node.

Returns

Type Description
string

A String value that represents the specified node’s state.

Remarks

The GetNodeState method returns the following values:

  • NotFound - the specified node was not found;
  • Collapsed - the specified node is collapsed;
  • Expanded - the specified node is expanded;
  • Child - the specified node has no child nodes.

Example

This example demonstrates how to use the ASPxClientTreeList.GetFocusedNodeKey  method to expand and collapse tree nodes based on the state of a node (collapsed or expanded). You can get the node state by calling the ASPxClientTreeList.GetNodeState method in the client-side ASPxTreeList.FocusedNodeChanged event. Demo limitation: if you close the topmost parent node and do not have other nodes except that one, you will have to expand this node by clicking the Expand Button.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxTreeList.v14.2, Version=14.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxTreeList" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v14.2, Version=14.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web" tagprefix="dx" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to use collapse/expand focused nodes on client side</title>
    <script>
        function OnFocusedNodeChange(s, e) {
            var nodeKey = s.GetFocusedNodeKey();
            var nodeState = s.GetNodeState(nodeKey);

            if (nodeState === "Collapsed")
                s.ExpandNode(nodeKey);
            else if (nodeState === "Expanded")
                s.CollapseNode(nodeKey);
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <dx:ASPxTreeList ID="TreeList"
            runat="server"
            AutoGenerateColumns="False" 
            DataSourceID="ProductsDataSource" 
            KeyFieldName="EmployeeID" 
            ParentFieldName="ReportsTo"
            Width="50%">
            <Columns>
                <dx:TreeListTextColumn FieldName="EmployeeID" VisibleIndex="0" ReadOnly="true"></dx:TreeListTextColumn>
                <dx:TreeListTextColumn FieldName="LastName" VisibleIndex="1"></dx:TreeListTextColumn>
                <dx:TreeListTextColumn FieldName="FirstName" VisibleIndex="2"></dx:TreeListTextColumn>
            </Columns>
            <SettingsBehavior AllowFocusedNode="true" FocusNodeOnLoad="false" />
            <ClientSideEvents FocusedNodeChanged="OnFocusedNodeChange" />
        </dx:ASPxTreeList>
        <br />

        <asp:AccessDataSource ID="ProductsDataSource" runat="server"
            DataFile="~/App_Data/nwind.mdb"
            SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [ReportsTo] FROM [Employees]">
        </asp:AccessDataSource>
    </form>
</body>
</html>
See Also