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

RadGrid ContextMenu

8 Answers 342 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Moustafa
Top achievements
Rank 1
Moustafa asked on 19 Aug 2008, 05:47 PM

Hi dear:

I'm  having the following scenario:

  • RadGrid with RadContextMenu [ master grid].
  • Edit form with other RadGrid(s) [children for the master].

the problem is that

when right clicking on row in the child grid it display the context menu of the master grid.

How can I do the following?

  • Prevent the context menu from being displayed when I right click the child rows grid.
  •  Or  displaying another one on the child grid.

Remark:
I try to create another context menu for the child grids but with no effect[ it also display the parent one]

this is done using :

  • Rad controls for asp.net ajax
  • framwork 3.5

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Aug 2008, 08:02 AM
Hello Moustafa,

You can prevent the ContextMenu from appearing on clicking a DetailTableRow by using the code below.You need to set the Name property for the MasterTable to achieve this.
aspx:
<MasterTableView DataSourceID="SqlDataSource1" Name="Master"  > 
 ---------- 
</MasterTableView> 
 <ClientSettings> 
 <ClientEvents OnRowContextMenu="RowContextMenu" /> 
 </ClientSettings> 

<script type="text/javascript" > 
       
        function RowContextMenu(sender, eventArgs) 
        { 
             if(eventArgs.get_tableView().get_name() == "Master") 
             { 
                var menu = $find("<%=RadContextMenu1.ClientID %>");                 
                var evt = eventArgs.get_domEvent();                
                if(evt.target.tagName == "INPUT" || evt.target.tagName == "A") 
                { 
                  return; 
                }                 
                menu.show(evt);               
             } 
         }         
         
</script> 

Thanks
Princy.

0
Moustafa
Top achievements
Rank 1
answered on 20 Aug 2008, 08:45 AM
Thanks you very much for your reply

what you suggest solved the first part successfully [prevent context menu from the child grid]

but

I'd like to be able to create another context menu for the child grid

when I try to do this it execute the javascript functions in the parent or master grid

thank you
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2008, 10:09 AM
Hi Moustafa,

You can create another ContextMenu for the ChildGrid and use the same logic as mentioned by Princy.

aspx:
<MasterTableView DataSourceID="SqlDataSource1" Name="Master"  >    
        <DetailTables>    
        <telerik:GridTableView AutoGenerateColumns="false" Name="Detail" DataSourceID="SqlDataSource1">     
              .....     
             </telerik:GridTableView>    
        </DetailTables>    
             ....     
 
 <telerik:RadContextMenu ID="RadContextMenu1" runat="server">  
        <Items> 
        <telerik:RadMenuItem Text="Click">  
        </telerik:RadMenuItem> 
        <telerik:RadMenuItem Text="Select">  
        </telerik:RadMenuItem> 
        </Items> 
 </telerik:RadContextMenu>    
 
 <telerik:RadContextMenu ID="RadContextMenu2" runat="server">  
          <Items> 
           <telerik:RadMenuItem Text="Add">  
           </telerik:RadMenuItem> 
         <telerik:RadMenuItem Text="Delete">  
        </telerik:RadMenuItem> 
        </Items> 
 </telerik:RadContextMenu> 


js:
<script type="text/javascript" > 
        function RowContextMenu(sender, eventArgs)  
        {  
             if(eventArgs.get_tableView().get_name() == "Master")  
             {  
                var menu = $find("<%=RadContextMenu1.ClientID %>");                  
                var evt = eventArgs.get_domEvent();                 
                if(evt.target.tagName == "INPUT" || evt.target.tagName == "A")  
                {  
                  return;  
                }                  
                menu.show(evt);                
             }  
               
            if(eventArgs.get_tableView().get_name() == "Detail")  
             {  
                var menu1 = $find("<%=RadContextMenu2.ClientID %>");                  
                var evt = eventArgs.get_domEvent();                 
                if(evt.target.tagName == "INPUT" || evt.target.tagName == "A")  
                {  
                  return;  
                }                  
                menu1.show(evt);                
             }  
         }           
</script> 

Thanks
Shinu.
0
Moustafa
Top achievements
Rank 1
answered on 20 Aug 2008, 11:02 AM
Oh

I did not include both the master and the details grid in the same page

the logic that currently created it like the following

  •  Web user control for RadGrid that acts as the parent grid
  •  Another web user control that acts as an edit form for the parent grid.
  • Inside the second web user control I create the child grids.
now what I need:
I need to be able to create a context menu for the child grid that is contained in the web user control that acts as the edit from for the parent grid.

I hope you understood my scenario
thanks for you

0
Princy
Top achievements
Rank 2
answered on 21 Aug 2008, 07:27 AM
Hello Moustafa,

To create a ContextMenu for a Grid in the WebUserControl use the same code as above with a different function name in the ascx page. Check out the following code.

ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<script type="text/javascript" > 
 function ChildRowContextMenu(sender, eventArgs) 
        {              
                var menu = $find("<%=RadContextMenu1.ClientID %>");                 
                var evt = eventArgs.get_domEvent();                
                if(evt.target.tagName == "INPUT" || evt.target.tagName == "A") 
                { 
                  return; 
                }                 
                menu.show(evt);                                        
       } 
</script> 
 
 
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" > 
<MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="True" > 
</MasterTableView> 
<ClientSettings> 
<ClientEvents OnRowContextMenu="ChildRowContextMenu" /> 
</ClientSettings> 
</telerik:RadGrid> 

Thanks
Princy.
0
moustafa
Top achievements
Rank 1
answered on 21 Aug 2008, 08:26 AM
when I do what you describe in the web user control of the child grid it give me a java script error "ChildRowContextMenu is undefined"

please note the following

I have 3 web controls

  1.  Contains the main Grid.
  2.  Contains the edit form as a web user control
  3.  Contains the child grid.

like this

Main Grid---                      (web user control [1])
                |
                |
                ----Edit Form      (web user control [2])
                        |
                        |
                        --ChildGrid  (web user control [3])

so i'd like to create the context menu for the 3rd Grid

first, It showed me the context menu of the MainGrid [1]

then with the help of telerik I was able to  disable it from appearing.

when I try to do what you said it gives me the error

"ChildRowContextMenu is undefined"

although its realy exists  and out of spelling errors.

thanks
0
Moustafa
Top achievements
Rank 1
answered on 21 Aug 2008, 08:30 AM
when I do what you describe in the web user control of the child grid it give me a java script error "ChildRowContextMenu is undefined"

please note the following

I have 3 web controls

  1.  Contains the main Grid.
  2.  Contains the edit form as a web user control
  3.  Contains the child grid.

like this

Main Grid---                      (web user control [1])
                |
                |
                ----Edit Form      (web user control [2])
                        |
                        |
                        --ChildGrid  (web user control [3])

so i'd like to create the context menu for the 3rd Grid

first, It showed me the context menu of the MainGrid [1]

then with the help of telerik I was able to  disable it from appearing.

when I try to do what you said it gives me the error

"ChildRowContextMenu is undefined"

although its realy exists  and out of spelling errors.

thanks
0
Princy
Top achievements
Rank 2
answered on 25 Aug 2008, 10:38 AM
Hello Moustafa,

I could not replicate this issue at my end. It would be better if you could paste your aspx sample code here.

Princy.
Tags
Grid
Asked by
Moustafa
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Moustafa
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
moustafa
Top achievements
Rank 1
Share this question
or