Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Table Driven Menus
Message
 
To
17/11/2009 15:48:19
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01435073
Message ID:
01435297
Views:
42
Thanks Bonnie!


>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
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Reply
Map
View

Click here to load this message in the networking platform