Hi Wade,
Thanks for posting your question here. The sample menu that we created for you is one level, even though it looks like two sections, but that's only because there are two special menu items.
The reason of knowing the levels is important is because data binding works on "levels", parent and child relationship is not necessary for one level menus, but is a must for multiple level menus. So if you have a parent child relationship like this in your DB:
My execution -> restaurant data, accounting home, ....
My people -> HR home, my forums, ....
When you populate from the DB, you will get restaurant data, accouting home... as popup sub menu items of "my execution", much the way like "Products" and "Product 1" in this sample:
http://www.essentialobjects.com/Demo/Default.aspx?path=Menu\_i0\_i8This is different than ASP.NET Menu, where you have a "static level" property that you can set to a number greater than one to display sub menu items statically.
In order to populate them into the same level, all the data in your data source must be on the same level: Records in the same table, child nodes on the same parent nodes in XML file, etc. If your contents in your database is hierarchical, you will need to write some code to "flat" them. One way to do this is to add them all into an ArrayList:
Code: C#
ArrayList items = new ArrayList();
//Put all rows in the first table into items
items.AddRange(ds.Tables[0].Rows);
//Put all rows in the second table into items
items.AddRange(ds.Tables[1].Rows);
The above code is only for showing you how to put contents of multiple tables into one ArrayList. In reality you may only want to put some rows into it. Of course if the whole purpose of your DB is to create the menu items then you can also change your DB structure from multiple parent-child tables into one table.
Once you have such a "flat" data source, you can bind it to our menu:
Code: C#
Menu1.DataSource = items;
Menu1.DataBind();
In this case, because the data source is an array list, the menu actually doesn't know what to do with each item in the array list. To solve this problem, you would handle the menu's ItemDataBound event. Our menu calls this event handler after it creates every menu item from the data source. So inside that handler you can do:
Code: C#
//Get the current data item
DataRowView row = (DataRowView)Menu1.DataItem;
//Modify the current menu item based on the data item
if (row["some_field"] == "some_value")
e.MenuItem.Image.Url = "some_url";
Note the code above is just for demonstration purpose and the if statement actually does not compile. So you will need to modify that.
When you put all those together, you would have a db-driven menu.
Thanks