PDA

View Full Version : [CLOSED] Adding Menu Items Runtime to DropDownField



WHISHWORKS
Sep 12, 2013, 1:58 PM
Hello,

I want to add element dynamically to DropDownField with AccordionLayout. I was trying to add menu items from code behind but it is not rendering on front end. Please find the code below




<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChartExample.aspx.cs" Inherits="Ext.NetSamples.ChartExample" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
MenuPanel menupnl1 = new MenuPanel();
menupnl1.Title = "Group1";

MenuPanel menupnl2 = new MenuPanel();
menupnl2.Title = "Group2";

Ext.Net.Menu menu1 = new Ext.Net.Menu();

Ext.Net.MenuItem menuitem1 = new Ext.Net.MenuItem();
menuitem1.Text = "Item1";
menu1.Add(menuitem1);

Ext.Net.MenuItem menuitem2 = new Ext.Net.MenuItem();
menuitem2.Text = "Item2";
menu1.Add(menuitem2);

menupnl1.Add(menu1);

Panel1.Items.Add(menupnl1);
Panel1.Items.Add(menupnl2);
}
</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">

</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:DropDownField ID="Field1" runat="server" TriggerIcon="Combo">
<Component>
<ext:Panel ID="Panel1" runat="server" Height="200" Layout="AccordionLayout" CollapseFirst="true">
<Items>
</Items>
</ext:Panel>
</Component>
</ext:DropDownField>
</form>
</body>
</html>

Daniil
Sep 12, 2013, 5:09 PM
Hi @WHISHWORKS,

Please add menu items direct to a MenuPanel.Menu.

Example

protected void Page_Load(object sender, EventArgs e)
{
MenuPanel menupnl1 = new MenuPanel();
menupnl1.Title = "Group1";

MenuPanel menupnl2 = new MenuPanel();
menupnl2.Title = "Group2";


Ext.Net.MenuItem menuitem1 = new Ext.Net.MenuItem();
menuitem1.Text = "Item1";

Ext.Net.MenuItem menuitem2 = new Ext.Net.MenuItem();
menuitem2.Text = "Item2";

menupnl1.Menu.Items.Add(menuitem1);
menupnl1.Menu.Items.Add(menuitem2);

Panel1.Items.Add(menupnl1);
Panel1.Items.Add(menupnl2);
}