This is a migrated thread and some comments may be shown as answers.

How to add Context menu to a TreeView Context Menu

1 Answer 192 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Dhamodharan
Top achievements
Rank 1
Dhamodharan asked on 23 Jan 2013, 01:50 PM
Hi 
I need to add a context menu to a treeviewcontext menu in asp.net Ajax. either to right on the tree view context or in the Menu format. The details to be bind from database.








Thanks

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 28 Jan 2013, 11:21 AM
Hello,

An easy and convenient way of adding dynamically a menu item to existing RadTreeViewContext menu would be to use the RadTreeView OnContextMenuItemClick server-side event handler as shown in the code snippet below:

//markup code

<telerik:RadTreeView ID="RadTreeView1" runat="server" OnContextMenuItemClick="RadTreeView1_ContextMenuItemClick">
<ContextMenus>
        <telerik:RadTreeViewContextMenu>
            <Items>
                <telerik:RadMenuItem Text="Context Menu 1"></telerik:RadMenuItem>
                <telerik:RadMenuItem Text="Context Menu 2"></telerik:RadMenuItem>
                <telerik:RadMenuItem Text="AddNewItem"></telerik:RadMenuItem>
            </Items>
        </telerik:RadTreeViewContextMenu>
    </ContextMenus>
</telerik:RadTreeView>

//code behind

protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
{
    if (e.MenuItem.Text == "AddNewItem")
    {
           //here goes your custom logic of accessing the data base and retrieve
           // new menu item details
        RadTreeView1.ContextMenus[0].Items.Add(new RadMenuItem("Dynamically added"));
    }
     
}

Regards,
Boyan Dimitrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Dhamodharan
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or