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

How to raise OnRowContextMenu event?

1 Answer 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 08 Aug 2008, 02:20 PM
Hi All!

I need this functionality:
    in RadGrid i have template column:
        
<telerik:GridTemplateColumn> 
<ItemTemplate> 
<asp:LinkButton ID="LinkButton7" runat="server">ContextMenu</asp:LinkButton> 
</ItemTemplate> 
</telerik:GridTemplateColumn> 

    and when user click on this linkbutton contextmenu will appear;

I think for this functionality i have to raise client event OnRowContextMenu on OnClienClick in LinkButton. But I dont know how.

Now i have contextmenu which appear when user click right mouse button.
And my jscript function is:

                    function RowContextMenu(sender, eventArgs)  
                    {  
                        var menu = $find("<%= RadMenu1.ClientID %>");  
                        var evt = eventArgs.get_domEvent();  
                          
                        var index = eventArgs.get_itemIndexHierarchical();  
                        document.getElementById("radGridClickedRowIndex").value = index;  
                          
                        sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);  
                          
                        menu.show(evt);  
                          
                        evt.cancelBubble = true;  
                        evt.returnValue = false;  
 
                        if (evt.stopPropagation)  
                        {  
                           evt.stopPropagation();  
                           evt.preventDefault();  
                        }  
                    } 

I can call this function on OnClienClick in LinkButton. But I dont know how i can send to this function second parameter (eventArgs).
I think the first parameter (sender) i can send to this function like this:

var sender = $find("<%= RadGrid1.ClientID %>"); 

But i cant understand how i can send second parameter...

Maybe anybody decided a similar task.

Thanks

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 12 Aug 2008, 06:13 AM
Hello Andy,

From the client click event handler, you can get a reference to the menu and show it explicitly.
For example, this may look something like:

.aspx
<telerik:GridTemplateColumn> 
<ItemTemplate> 
<asp:Label runat="server" ID="Label1" Text="ShowMenu" onclick="showMenu()">  
</asp:Label> 
</ItemTemplate> 
</telerik:GridTemplateColumn> 

and in the client-side handler:

.Js
  function showMenu()  
       {         
          var menu = $find("<%= RadContextMenu2.ClientID %>");     
          menu.show(window.event);  
        } 

I hope this suggestion helps.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or