Hi,
The first thing I noticed about this control was that it didn't include the Menu's CssClass property in the html. This means that all the Menu control are rendered the same. As I use a couple of Menu's on some pages and I need them to render differently I had to include the CssClass property. What I did was in the MenuAdapters was....
Replace the RenderBeginTag with the following - notice that I add a class variable controlCssClass.
string controlCssClass = null;
protected override void RenderBeginTag(HtmlTextWriter writer)
{
if (Extender.AdapterEnabled)
{
// add orig CSS class
if (!string.IsNullOrEmpty(Control.CssClass))
{
controlCssClass = Control.CssClass + " ";
}
Extender.RenderBeginTag(writer, controlCssClass + "AspNet-Menu-" + Control.Orientation.ToString());
}
else
{
base.RenderBeginTag(writer);
}
}
Replace BuildItems method with
private void BuildItems(MenuItemCollection items, bool isRoot, HtmlTextWriter writer)
{
if (items.Count > 0)
{
writer.WriteLine();
writer.WriteBeginTag("ul");
if (isRoot)
{
writer.WriteAttribute("class", controlCssClass + "AspNet-Menu");
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
foreach (MenuItem item in items)
{
BuildItem(item, writer);
}
writer.Indent--;
writer.WriteLine();
writer.WriteEndTag("ul");
}
}
Replace GetItemClass with
private string GetItemClass(Menu menu, MenuItem item)
{
string value = "AspNet-Menu-NonLink";
if (item != null)
{
if (((item.Depth < menu.StaticDisplayLevels) && (menu.StaticItemTemplate != null)) ||
((item.Depth >= menu.StaticDisplayLevels) && (menu.DynamicItemTemplate != null)))
{
value = "AspNet-Menu-Template";
}
else if ((item.NavigateUrl.Length > 0) || item.Selectable)
{
value = "AspNet-Menu-Link";
}
if (item.Selected)
{
value += " AspNet-Menu-Selected";
}
else if (IsChildItemSelected(item))
{
value += " AspNet-Menu-ChildSelected";
}
else if (IsParentItemSelected(item))
{
value += " AspNet-Menu-ParentSelected";
}
}
// add control css class
return controlCssClass + value;
}
Replace the first few lines of BuildItem with
private void BuildItem(MenuItem item, HtmlTextWriter writer)
{
Menu menu = Control as Menu;
if ((menu != null) && (item != null) && (writer != null))
{
writer.WriteLine();
writer.WriteBeginTag("li");
writer.WriteAttribute("class", controlCssClass + (item.ChildItems.Count > 0 ? "AspNet-Menu-WithChildren" : "AspNet-Menu-Leaf"));
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
writer.WriteLine();
-------------------------------------
Damien McGivern
http://nimtug.org
-------------------------------------