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

RadMenuItem - How to get a hold on the associated item during ItemClick event?

1 Answer 40 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Kien
Top achievements
Rank 1
Kien asked on 04 Apr 2012, 04:55 PM
Hi,

I was referring to the following article to add a custom RadMenuItem to the GridContextMenu of the FileExplorer.
http://www.telerik.com/help/aspnet-ajax/radfileexplorer-add-custom-button-context-menu-item.html

Instead of handling the "Click" event with javascript, I'd like to handle it with code behind.

The problem is I can't seem to get a reference to the current item. I'd like to get its path.
I tried using RadMenuItem.DataItem but it returns null. I then read that it is only usable on DataBinding/Bound events.

Can someone point me in the right direction please?

Thank you.

Here's the code: (please note that "ucFileExplorer" is the reference to the RadFileExplorer user control that is currently on the page)
protected void Page_Load(object sender, EventArgs e)
{
    RadMenuItem menuAlertMe = new RadMenuItem("Alert Me");
    menuAlertMe.Value = "AlertMe";
    ucFileExplorer.GridContextMenu.Items.Add(menuAlertMe);
    ucFileExplorer.GridContextMenu.ItemClick += new RadMenuEventHandler(GridContextMenu_ItemClick);
}
 
private void GridContextMenu_ItemClick(object sender, RadMenuEventArgs e)
{
    RadMenuItem menuItem = e.Item as RadMenuItem;
    if (menuItem.Value == "AlertMe")
    {
       // I want to get a hold of the current item of the Grid so I can process it...
    }
}

1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 09 Apr 2012, 12:00 PM
Hi Kien,

I already answered your support ticket on the subject. For convenience I will paste my answer here as well.

RadFileExplorer does not provide information regarding the Grid's selected items on the server over postback. Nevertheless, you can achieve the required result by handling the context menu's ItemClick client-side event, get the selected item from the grid and pass it on the server using AJAX request.

And example of how to achieve this is available in the following KB article:

Custom field in the GridContextMenu. Pass the selected item's path to the server when the field is clicked.


Kind regards,
Dobromir
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
Menu
Asked by
Kien
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or