The requested page is not available for the requested platform. You are viewing the content for Default platform.

ASPxClientTreeView.SetSelectedNode(node) Method

Selects the specified node within the ASPxTreeView control on the client side.

Declaration

SetSelectedNode(node: ASPxClientTreeViewNode): void

Parameters

Name Type Description
node ASPxClientTreeViewNode

An ASPxClientTreeViewNode object specifying the node to select.

Remarks

If the ASPxTreeView.AllowSelectNode property is set to true, end-users are allowed to select nodes via mouse clicks. The ASPxTreeView also provides the ability to select nodes on the client side via code. You can use the SetSelectedNode method for this purpose. Note that only one node can be selected within an ASPxTreeView control at the same time.

To make none of the nodes selected within a ASPxTreeView control, pass null as the method's parameter.

To learn more, see the Selection topic.

Examples

This example demonstrates how to find a node by its text on the client side.

In the example we use the GetNodeByText(text) method to search for the required node. If a node has been found, the code iterates through parent nodes to expand them using the SetExpanded(value) method. After that the found note is selected using the SetSelectedNode(node) method. Note, that the ASPxTreeView's AllowSelectNode property is set to true to allow node selection.

<script>
function FindNode(s, e) {

    //Check the input data
    if (textbox.GetText()==''){
        alert('Please, input name of a node');
        return;
    }
    if (treeview.GetNodeByText(textbox.GetText()) == null){
        alert('The ' + textbox.GetText() + ' node was not found');
        return;
    }
    var node = treeview.GetNodeByText(textbox.GetText());

    //Iterate through the parent nodes to expand them
    var nodesparent = node.parent;
    while(nodesparent != null) {
        nodesparent.SetExpanded(true);
        nodesparent = nodesparent.parent
    }

    //Select the found node
    treeview.SetSelectedNode(node);
}    
</script>
<dx:ASPxTreeView ID="ASPxTreeView1" runat="server" ClientInstanceName="treeview" DataSourceID="XmlDataSource1" AllowSelectNode="True">
</dx:ASPxTreeView>
<br />
<dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="Input the node's text (e.g. 'News')">
</dx:ASPxLabel>
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" ClientInstanceName="textbox" Width="170px">
</dx:ASPxTextBox>
<br />
<dx:ASPxButton ID="ASPxButton1" runat="server" ClientInstanceName="searchbutton"
    Text="Find" AutoPostBack="False">
    <ClientSideEvents Click="FindNode"/>
</dx:ASPxButton>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/MenuTabbedMenu.xml"
    OnTransforming="XmlDataSource1_Transforming" XPath="/mainmenu/item">
</asp:XmlDataSource>
See Also