How to find a node by its text using the GetNodeByText method
2013-02-22 06:30
731 查看
his example demonstrates how to find a node by its text on the client side.
In the example we use the GetNodeByText 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 method.
After that the found note is selected using the SetSelectedNode method.
Note, that the ASPxTreeView's AllowSelectNode property
is set to true to allow node selection.
In the example we use the GetNodeByText 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 method.
After that the found note is selected using the SetSelectedNode method.
Note, that the ASPxTreeView's AllowSelectNode property
is set to true to allow node selection.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="DevExpress.Web.ASPxHtmlEditor.v10.2, Version=10.2.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxHtmlEditor" TagPrefix="dx" %> <%@ Register Assembly="DevExpress.Web.ASPxSpellChecker.v10.2, Version=10.2.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxSpellChecker" TagPrefix="dx" %> <%@ Register Assembly="DevExpress.Web.v10.2, Version=10.2.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxTreeView" TagPrefix="dx" %> <%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.2, Version=10.2.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <!--region #Markup--> <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> <!--endregion #Markup--> </div> </form> </body> </html>
相关文章推荐
- Are you looking for a way to get the entire text of a word document into a RichEdit without using the Clipboard?
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本
- How to get the nearest parent node given a text node in jQuery?
- [Drupal] How to get the real path of a node, no matter it is a path or a url alias
- virtual memory layout and how to get it by the correspoinding functuon
- [转]How to find who is using / eating up the Virtual Address Space on your SQL Server
- #146 – Use GetValueSource Method to Find the Source of a Dependency Property Value
- How can selenium web driver get to know when the new window has opened and then resume its execution
- How to get response content with specified post data by post method
- How to populate the datagrid on background thread with data binding by using Visual C#
- C++ How to avoid the enter key when using cin and getline
- How to get the query string by javascript?
- file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it 的解决
- The method getTextContent() is undefined for the type Node
- How to Change the DBID and the DBNAME by using NID [ID 224266.1]
- How to find the log I want when using 'git log'
- How to get the file's icon using C++ - 用C++如何获取文件的图标
- How to get a type in C++ when its template argument is the argument
- Working on your thesis: how to get started and how to keep it going?
- 项目报错:The method getTextContent() is undefined for the type Node