child menus orientation

  • Thread starter Thread starter thersitz
  • Start date Start date
thersitz,

Unfortunately it is not possible to set the Orientation of a child MenuItem.
You can simulate the menu from the site that you mentioned by injecting html
into the Text property of a MenuItem.

See the attached example for details. The following page should be named
Menus.aspx

Jason Vermillion

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack){
PopulateMenu();
}
}

private void PopulateMenu()
{
MenuItem mnu;
MenuItem childmnu;
char curchar;
System.Text.StringBuilder sb;
string baseurl = @"<a
href=""Menus.aspx?search_in={0}&search_by={1}"">{1}&nbsp;</a>";
string search_in = "";
string html = "";
string tmp = "";
string[] aryMenues = { "TITLE", "DATE", "FORMAT", "SUBJECT", "NAME" };

mnuNav.Items.Clear();

foreach (string item in aryMenues)
{
mnu = new MenuItem(item, item);
mnu.Selectable = false;

if (item == "TITLE" || item == "NAME")
{
// get the search_in query string
search_in = (item == "TITLE") ? "title" : "name";
// Generate some links from A-Z
sb = new System.Text.StringBuilder(1024);
for (int i = 65; i <= 90; i++)
{
curchar = (char)i;
// Append the next letter in the alphabet(<a
href="...">A</a>)
sb.AppendFormat(baseurl, search_in, curchar.ToString());
}
html = sb.ToString();

childmnu = new MenuItem(html, "A-Z");
mnu.ChildItems.Add(childmnu);
}
else if (item == "DATE")
{
int delta = 3;
for (int i = 0; i < 10; i++)
{
tmp = string.Format("{0}-{1}", 2010 - (i + 1) * delta +
1, 2010 - i * delta);
childmnu = new MenuItem(tmp, tmp);
mnu.ChildItems.Add(childmnu);
}
}
else if (item == "FORMAT")
{
mnu.ChildItems.Add(new MenuItem("Book", "BOOK"));
mnu.ChildItems.Add(new MenuItem("E-Book", "E-BOOK"));
mnu.ChildItems.Add(new MenuItem("Dvd", "DVD"));
mnu.ChildItems.Add(new MenuItem("Audio", "AUDIO"));
}
else if (item == "SUBJECT")
{
mnu.ChildItems.Add(new MenuItem("Elephants", "Elephants"));
mnu.ChildItems.Add(new MenuItem("Fish", "Fish"));
mnu.ChildItems.Add(new MenuItem("Ants", "Ants"));
mnu.ChildItems.Add(new MenuItem("Jello", "Jello"));
}
mnuNav.Items.Add(mnu);
}

}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu Test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu ID="mnuNav" runat="server" Orientation="Horizontal">
</asp:Menu>
</div>
</form>
</body>
</html>
 
Back
Top