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

Dynamically Generate RadContextMenu from SQL Server Table using Cell Value of the RadGrid (on which the user clicked to get the Context Menu) as a parameter

1 Answer 63 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Nishant asked on 02 Jul 2012, 11:40 PM

I'm trying to Dynamically generate the RadContextMenu based on the contents of the Cell in RadGrid on which the user clicks. The menu items are stored in the SQL Sever database. Below is my client side code :

function RowContextMenu(sender, eventArgs) {
                var evt = eventArgs.get_domEvent();
                if ( == "INPUT" || == "A") {
                var index = eventArgs.get_itemIndexHierarchical();
                var row = sender.get_masterTableView().get_dataItems()[index];
                var current_status = sender.get_masterTableView().getCellByColumnUniqueName(row, "Current_Status").innerHTML;
                var process_status = sender.get_masterTableView().getCellByColumnUniqueName(row, sender.get_masterTableView().get_columns()[].get_uniqueName()).innerHTML;
                var process_area = //write code to get the column header of the selected cell
                document.getElementById("radGridClickedRowIndex").value = index;
                sender.get_masterTableView().selectItem(row.get_element(), true);
                var menu = $find("<%=RadMenu1.ClientID %>");
                evt.cancelBubble = true;
                evt.returnValue = false;
                if (evt.stopPropagation) {

Now i want to pass the values current_Status, process_status and process_area to SQL server and get the list of actions to populate in the context menu.

Below are some snippets of the ASPX code:
<asp:SqlDataSource ID="ActionsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MetadataCS %>"
    ProviderName="<%$ ConnectionStrings:MetadataCS.ProviderName %>" SelectCommand="SELECT [Action] FROM [FileStatusActions] WHERE (([Process_Area] = @Process_Area) AND ([Current_Status] = @Current_Status) AND ([Process_Status] = @Process_Status))">
        <asp:Parameter Name="Process_Area" Type="String" />
        <asp:Parameter Name="Current_Status" Type="String" />
        <asp:Parameter Name="Process_Status" Type="String" />
<telerik:RadContextMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick" OnClientShowing="showContextMenu"
    DataSourceID="ActionsDataSource" DataTextField="Action" DataValueField="Action" AppendDataBoundItems="true"
    EnableRoundedCorners="true" EnableShadows="true">
        <telerik:RadMenuItem Text="Dynamic Menu" />

Please help me achieve the desired functionality using either client side/server side code ? I am also willing to use XML files to load menu instead of database if feasible/possible.


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 05 Jul 2012, 11:11 AM
Hello Nishant,

If you have the information only on the server, you would need to add the items server-side. Try the following:

1) Wrap the RadGrid in a RadAjaxPanel together with the RadContextMenu OR use a RadAjaxManager to update the grid and the menu.
2) Wire the client-side OnRowContextMenu event of RadGrid, collect the needed information and pass it to the server using the ajaxRequest method of the respective RadAjax control.
3) On the server, use the passed information to populate the menu and register a client script block that will show the menu.

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.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question