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

Different contexts menus for differents grids

2 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 17 May 2011, 04:42 PM
Hi

I have a page with three grid et I want to associate to them a differente contextMenu. In fact, I want the first grid to add the item "add", "Edit" and "Delete" and the two others grid to contain "Edit" and "Delete". Seem pretty easy to do to me, but I'm unable to know wich grid had been clicked. I alreary tried this demo, but it didn't help this much, cause this demo work with only one grid. May someone help me ? Thanks

David

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 May 2011, 07:29 AM
Hello David,

One approach is to add two Context menus and call them based on the ID of the selected  RadGrid. You can get the corresponding Client ID using the property sender.ClientID. Here is the sample code that I tried. Hope this helps you.
aspx:
<telerik:RadGrid runat="server" ID="RadGrid2" DataSourceID="SqlDataSource2" AutoGenerateEditColumn="true">
 <ClientSettings>
        <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>
</ClientSettings>
 </
telerik:RadGrid>
 <
telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
            AutoGenerateEditColumn="true">
   <ClientSettings>
      <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>
   </
ClientSettings>

 </
telerik:RadGrid>
 <telerik:RadContextMenu ID="RadMenu1" runat="server">
   <Items>
       <telerik:RadMenuItem Text="Add" />
       <telerik:RadMenuItem Text="Edit" />
       <telerik:RadMenuItem Text="Delete" />
  </Items>
 </
telerik:RadContextMenu>
 <
telerik:RadContextMenu ID="RadMenu2" runat="server">
    <Items>
        <telerik:RadMenuItem Text="Add" />
        <telerik:RadMenuItem Text="Edit" />
    </Items>
 </
telerik:RadContextMenu>

Javascript:
<script type="text/javascript">
  function RowContextMenu(sender, args)
      {
      var menu;
       if (sender.ClientID == "RadGrid1")///Checking for the client ID
           {
          menu = $find("<%=RadMenu1.ClientID %>");
        }
        else
                     {
            menu = $find("<%=RadMenu2.ClientID %>");
        }
           var  evt = args.get_domEvent();
           menu.show(evt);
      . . . . . .
    }
</script>

Thanks,
Princy.
0
David
Top achievements
Rank 1
answered on 18 May 2011, 02:45 PM
It exactly what I need. Can't be more perfect like example
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
David
Top achievements
Rank 1
Share this question
or