Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Table Driven Menus
Message
De
17/11/2009 15:48:19
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01435073
Message ID:
01435289
Vues:
68
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform