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

2 posts, 0 answers
  1. Kien
    Kien avatar
    3 posts
    Member since:
    Mar 2012

    Posted 04 Apr 2012 Link to this post

    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...
        }
    }
  2. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 09 Apr 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top