Can someone provide sample code in which a WebDataMenu is coded completely on the server-side? By completely, I mean that server side code creates the WebDataMenu and makes all modifications to it, and there are no <WebDataMenu> tags in the markup files that ship with our application. We want to use a WebDataMenu in each cell of a column in a WebDataGrid. Each of those instances of WebDataMenu needs to be created during the grid's OnInitializeRow event because each row's menu contents are dependent upon the data in the row and complex server side logic. We were able to accomplish all of this with UltraWebMenu (which Infragistics retired after WebDataMenu was introduced), but we need an example of how to do it with WebDataMenu.
What we are looking to achieve is easiest to show with screenshots from our app that uses Infragistics' old UltraWebMenu and UltraWebGrid controls. In these screenshots, I've obfuscated our data with black and red marks for confidentiality. Each screenshot shows the same grid but with a different context menu appearing over it. The red mark indicates which cell was clicked to make the context menu appear. Notice that the contents of the context menu differ depending on which row was clicked (the contents of the menu are dependent on the data in the row and some server-side logic).
Now we are trying to replicate the above using WebDataMenu and WebDataGrid. Per your reply, I put the following in my markup inside the <Columns> element of a WebDataGrid:
<iggrid:TemplateDataField Key="MenuAction" Width="10%">
<Header Text="Ref Number"></Header>
<ItemTemplate>
<asp:Label ID="lblLaunchMenu" runat="server" Text="Launch Menu" Font-Underline="true" ForeColor="Blue" CssClass="Label" Visible="false" />
<igmenu:WebDataMenu ID="mnuActionMenu" runat="server" IsContextMenu="true">
<Items>
<igmenu:DataMenuItem>
<Template>
<p>Dummy Menu Item</p>
</Template>
</igmenu:DataMenuItem>
</Items>
</igmenu:WebDataMenu>
</ItemTemplate>
</iggrid:TemplateDataField>
In the code behind, in the handler for the grid's InitializeRow event, I have the following:
WebDataMenu actionMenu = row.Items.FindItemByKey(COL_ACTION).FindControl("mnuActionMenu") as WebDataMenu;
actionMenu.ID = "menuForAccount" + accountNumber // give each grid row's menu a unique ID, account number is different in each grid row
//this is pseudocode for loop that adds menu items to each menu, the important point here is that "i" makes each menu item unique within a given menu
int i = 0;
loop
actionMenu.Items.Add(new DataMenuItem { Enabled = true, Visible = true, Text = "foo" + i, NavigateUrl = "/bar/" + i }
i++;
end loop
var fullMenuName = ClientID.Replace("_", "") + actionMenu.ID;
lblLaunchMenu.Attributes.Add("onmouseup", "BLOCKED SCRIPTif(event.button == 0 || event.button == 1){igmenu_showMenu('" + fullMenuName + "', event);event.returnValue = false;event.cancelBubble=true;}");
We copied the last two line above from our app that uses the old Infragistics controls, but when igmenu_showMenu executes, it can't find an element whose id is fullMenuName, so it pops up this message (I've debugged into igmenu_showMenu and saw where this happens):
So that's where we are at this point. Any help would be appreciated.
Hi Michael,
This behavior can be achieved by using a TemplatedDataField containing a WebDataMenu. Here is an example of the markup of a WebDataMenu within a WebDataGrid:
<ig:TemplateDataField Key="WDM"> <ItemTemplate> <ig:WebDataMenu runat="server" ID="WDM"> <Items> <ig:DataMenuItem> <Template> <p>Item</p> </Template> </ig:DataMenuItem> </Items> </ig:WebDataMenu> </ItemTemplate></ig:TemplateDataField>
Within the Initialize Row event, we can obtain the control by using the FindControl method and using the control's ID we set in the markup. In this case, the WebDataMenu's ID is WDM. Here's an example of the code behind:
protected void WDG1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e){ Control control = e.Row.Items[2].FindControl("WDM");}
I am attaching a sample I used to test this behavior.
Also, can you provide more details on what you are looking to achieve with the WebDataMenu within the WebDataGrid.
Let me know if I can be of further assistance.