Hi,
Am doing mega drop down menu, where the menu items and sub items are driven from XML file.Actually my wish is drop down should not appear if no sub items are present under a menu item.But in this case am getting an empty drop down.Please let me know how to get out of this.
Code snippet is as folows and the following attachment is my xml file.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RadMenu1.LoadContentFile("menu3.xml");
RadMenu1.DataBind();
}
}
protected void RadMenu1_DataBound(object sender, EventArgs e)
{
RadMenu menu = (RadMenu)sender;
menu.Width = 880;
menu.Height = 35;
foreach (RadMenuItem item in menu.Items)
{
RadSiteMap sm = new RadSiteMap();
PopulateSiteMap(sm, null, item);
//sitemap settings to have the menu items appear in columns
SiteMapLevelSetting rootLevelSetting = new SiteMapLevelSetting(0);
rootLevelSetting.ListLayout.RepeatColumns = 1;
rootLevelSetting.ListLayout.RepeatDirection = SiteMapRepeatDirection.Horizontal;
sm.LevelSettings.Add(rootLevelSetting);
item.Items.Clear();
RadMenuItem childItem = new RadMenuItem();
childItem.Width = 880;
Panel catWrapper = new Panel();
catWrapper.CssClass = "Wrapper";
catWrapper.Width = Unit.Pixel(870);
catWrapper.Controls.Add(sm);
childItem.Controls.Add(catWrapper);
item.Items.Add(childItem);
}
}
private static void PopulateSiteMap(RadSiteMap sm, RadSiteMapNode node, RadMenuItem item)
{
if (node == null)
{
foreach (RadMenuItem child in item.Items)
{
node = new RadSiteMapNode(child.Text, child.NavigateUrl);
sm.Nodes.Add(node);
if (child.Items.Count > 0)
{
PopulateSiteMap(sm, node, child);
}
}
}
else
{
foreach (RadMenuItem child in item.Items)
{
node.Nodes.Add(new RadSiteMapNode(child.Text, child.NavigateUrl));
if (child.Items.Count > 0)
{
PopulateSiteMap(sm, node, child);
}
}
}
}
Thanks & Regards
Mohanram Poola
Am doing mega drop down menu, where the menu items and sub items are driven from XML file.Actually my wish is drop down should not appear if no sub items are present under a menu item.But in this case am getting an empty drop down.Please let me know how to get out of this.
Code snippet is as folows and the following attachment is my xml file.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RadMenu1.LoadContentFile("menu3.xml");
RadMenu1.DataBind();
}
}
protected void RadMenu1_DataBound(object sender, EventArgs e)
{
RadMenu menu = (RadMenu)sender;
menu.Width = 880;
menu.Height = 35;
foreach (RadMenuItem item in menu.Items)
{
RadSiteMap sm = new RadSiteMap();
PopulateSiteMap(sm, null, item);
//sitemap settings to have the menu items appear in columns
SiteMapLevelSetting rootLevelSetting = new SiteMapLevelSetting(0);
rootLevelSetting.ListLayout.RepeatColumns = 1;
rootLevelSetting.ListLayout.RepeatDirection = SiteMapRepeatDirection.Horizontal;
sm.LevelSettings.Add(rootLevelSetting);
item.Items.Clear();
RadMenuItem childItem = new RadMenuItem();
childItem.Width = 880;
Panel catWrapper = new Panel();
catWrapper.CssClass = "Wrapper";
catWrapper.Width = Unit.Pixel(870);
catWrapper.Controls.Add(sm);
childItem.Controls.Add(catWrapper);
item.Items.Add(childItem);
}
}
private static void PopulateSiteMap(RadSiteMap sm, RadSiteMapNode node, RadMenuItem item)
{
if (node == null)
{
foreach (RadMenuItem child in item.Items)
{
node = new RadSiteMapNode(child.Text, child.NavigateUrl);
sm.Nodes.Add(node);
if (child.Items.Count > 0)
{
PopulateSiteMap(sm, node, child);
}
}
}
else
{
foreach (RadMenuItem child in item.Items)
{
node.Nodes.Add(new RadSiteMapNode(child.Text, child.NavigateUrl));
if (child.Items.Count > 0)
{
PopulateSiteMap(sm, node, child);
}
}
}
}
Thanks & Regards
Mohanram Poola