Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Table Driven Menus
Message
From
17/11/2009 15:48:19
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01435073
Message ID:
01435289
Views:
67
This is pieced together from some stuff I've done (left out some stuff that wasn't easy to tweak for my test purposes to show you a sample). It works, although you will probably want to tweak it.
private void TestMenuAddItemsDynamically()
{
	MenuItem item;
	for (int i = 0; i < this.oData.Rows.Count; i++)
	{
		item = new MenuItem(this.oData.Rows[i]["description"].ToString());
		this.AddMenuItem("Dynamic Menu", item);
	}
}
// Generic method for adding to any Menu
private void AddMenuItem(string name, MenuItem item)
{
	string lookForName = name.Replace("&", "");

	// Find top-level menu item
	MenuItem addTo = null;
	for (int i = 0; i < this.Menu.MenuItems.Count; i++)
	{
		MenuItem topLevel = this.Menu.MenuItems[i];
		if (string.Compare(topLevel.Text.Replace("&", ""), lookForName, true) == 0)
		{
			addTo = topLevel;
			break;
		}
	}

	// Was a top-level menu item found?
	if (addTo == null)
	{
		addTo = new MenuItem(name);
		this.Menu.MenuItems.Add(addTo);
		addTo.Index = this.Menu.MenuItems.Count - 2;
	}

	addTo.MenuItems.Add(item);
}
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform