Current filter:
                                You should refresh the page.
                                Support Center

                                Node-specific context menu


                                This example shows how to attach a context menu to an ASPxTreeList v2010 vol 1.5.
                                Menus can have specific items for different nodes.

                                See also:
                                How to edit the ASPxTreeList using the context menu

                                You must  log in  or  register  to leave comments
                                Select file
                                • Default.aspx
                                • Default.aspx.cs
                                Select language
                                • C#
                                • VB.NET
                                Select version
                                • v2013 vol 1.4 - v2013 vol 2.9
                                • v2010 vol 1.5 - v2012 vol 2.16
                                • v2008 vol 1.2 - v2010 vol 1.5
                                <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
                                <%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.1, Version=, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
                                    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
                                <%@ Register Assembly="DevExpress.Web.v10.1, Version=, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
                                    Namespace="DevExpress.Web.ASPxMenu" TagPrefix="dx" %>
                                <%@ Register Assembly="DevExpress.Web.ASPxTreeList.v10.1, Version=, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
                                    Namespace="DevExpress.Web.ASPxTreeList" TagPrefix="dx" %>
                                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
                                <html xmlns="">
                                <head runat="server">
                                    <title>Node-specific context menu</title>
                                    <script type="text/javascript" language="javascript">
                                        var key = "";
                                        function OnContextMenu (s, e) {
                                            if (e.objectType == "Node") {
                                                key = e.objectKey;
                                                /* prepare popup menu */                
                                                var state = tree.GetNodeState(e.objectKey);
                                                popupMenu.GetItem(0).SetEnabled(state != "Child" && state != "NotFound");  
                                                popupMenu.GetItem(1).SetEnabled(state == "Child" || state == "NotFound");                
                                                popupMenu.ShowAtPos(ASPxClientUtils.GetEventX(e.htmlEvent), ASPxClientUtils.GetEventY(e.htmlEvent));                
                                        function menu_OnItemClick(s, e) {
                                            switch(e.item.index) {
                                                case 0:
                                                    var state = tree.GetNodeState(key);
                                                    if (state == "Expanded")
                                                case 1:
                                                    alert("Node key is: " + key);
                                                case 2:
                                                    alert("ASPxTreeList v2010 vol 1.5");
                                    <form id="form1" runat="server">
                                            <dx:ASPxTreeList ID="tree" runat="server" AutoGenerateColumns="False" DataSourceID="ads"
                                                KeyFieldName="ID" ParentFieldName="ParentID" ClientInstanceName="tree">
                                                    <dx:TreeListDataColumn FieldName="Department" VisibleIndex="0" />
                                                    <dx:TreeListDataColumn FieldName="Location" VisibleIndex="1" />
                                                <SettingsBehavior AutoExpandAllNodes="true" />
                                                <ClientSideEvents ContextMenu="OnContextMenu" />
                                            <dx:ASPxPopupMenu ID="popupMenu" runat="server" ClientInstanceName="popupMenu">
                                                <ClientSideEvents ItemClick="menu_OnItemClick" />
                                                    <dx:MenuItem Text="Expand / Collapse" />
                                                    <dx:MenuItem Text="Get node info..." />
                                                    <dx:MenuItem Text="About..." />
                                            <asp:AccessDataSource ID="ads" runat="server" DataFile="~/App_Data/Departments.mdb"
                                                SelectCommand="SELECT [ID], [ParentID], [Department], [Location] FROM [Departments]">

                                To start a chat you should create a support ticket

                                If you need additional product information, write to us at or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners