ASP.Net/Components/Menu
Содержание
Hyper link Menu item (C#)
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Menu HyperLink</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu
id="Menu1"
Runat="server">
<Items>
<asp:MenuItem
Text="Products"
NavigateUrl="http://www.nfex.ru" />
<asp:MenuItem
Text="Services"
NavigateUrl="http://www.nfex.ru">
<asp:MenuItem
Text="Training"
NavigateUrl="http://www.nfex.ru" />
<asp:MenuItem
Text="Consulting"
NavigateUrl="http://www.nfex.ru" />
</asp:MenuItem>
</Items>
</asp:Menu>
</div>
</form>
</body>
</html>
Menu selected action (C#)
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
lblMessage.Text = "You selected " + Menu1.SelectedValue;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Menu LinkButton</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu
id="Menu1"
OnMenuItemClick="Menu1_MenuItemClick"
Runat="server">
<Items>
<asp:MenuItem
Text="Products Page"
Value="Products" />
<asp:MenuItem
Text="Services Page"
Value="Services">
<asp:MenuItem
Text="Training Page"
Value="Training" />
<asp:MenuItem
Text="Consulting Page"
Value="Consulting" />
</asp:MenuItem>
</Items>
</asp:Menu>
<hr />
<asp:Label
id="lblMessage"
EnableViewState="false"
Runat="server" />
</div>
</form>
</body>
</html>
Menu template (C#)
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
lblMessage.Text = Menu1.SelectedValue;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<style type="text/css">
.menuItem
{
color:black;
border:Solid 1px Gray;
background-color:#c9c9c9;
padding:2px 5px;
}
</style>
<title>Menu Templates</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu
id="Menu1"
OnMenuItemClick="Menu1_MenuItemClick"
Orientation="Horizontal"
StaticMenuItemStyle-CssClass="menuItem"
DynamicMenuItemStyle-CssClass="menuItem"
Runat="server">
<StaticItemTemplate>
<%# Eval("Text") %>
(<%# Eval("ChildItems.Count") %>)
</StaticItemTemplate>
<DynamicItemTemplate>
<%# Eval("Text") %>
(<%# Eval("ChildItems.Count") %>)
</DynamicItemTemplate>
<Items>
<asp:MenuItem Text="Produce">
<asp:MenuItem Text="Apples" />
<asp:MenuItem Text="Oranges" />
</asp:MenuItem>
<asp:MenuItem Text="Beverages">
<asp:MenuItem Text="Soda">
<asp:MenuItem Text="Coke" />
<asp:MenuItem Text="Pepsi" />
</asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>
<hr />
<asp:Label
id="lblMessage"
EnableViewState="false"
Runat="server" />
</div>
</form>
</body>
</html>
Menu with style (C#)
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<style type="text/css">
.menuLevel1
{
font:40px Arial,Sans-Serif;
}
.menuLevel2
{
font:20px Arial,Sans-Serif;
}
.menuLevel3
{
font:10px Arial,Sans-Serif;
}
</style>
<title>Menu Level Styles</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu
id="Menu1"
Runat="server">
<LevelMenuItemStyles>
<asp:MenuItemStyle CssClass="menuLevel1" />
<asp:MenuItemStyle CssClass="menuLevel2" />
<asp:MenuItemStyle CssClass="menuLevel3" />
</LevelMenuItemStyles>
<Items>
<asp:MenuItem Text="Produce">
<asp:MenuItem Text="Apples" />
<asp:MenuItem Text="Oranges" />
</asp:MenuItem>
<asp:MenuItem Text="Beverages">
<asp:MenuItem Text="Soda">
<asp:MenuItem Text="Coke" />
<asp:MenuItem Text="Pepsi" />
</asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>
</div>
</form>
</body>
</html>
Menu XML Complex (C#)
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Menu XML Complex</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu
id="Menu1"
DataSourceID="srcMenu"
Runat="server">
<DataBindings>
<asp:MenuItemBinding
DataMember="category"
TextField="text" />
<asp:MenuItemBinding
DataMember="item"
TextField="text"
ValueField="price" />
</DataBindings>
</asp:Menu>
<asp:XmlDataSource
id="srcMenu"
DataFile="MenuComplex.xml"
Runat="server" />
</div>
</form>
</body>
</html>
<%--
<?xml version="1.0" encoding="utf-8" ?>
<menu>
<category text="appetizer">
<item text="soup" price="2.56" />
<item text="cheese" price="7.23" />
</category>
<category text="entree">
<item text="duck" price="9.21" />
<item text="chicken" price="4.56" />
</category>
<category text="dessert">
<item text="cake" price="3.43" />
<item text="pie" price="5.46" />
</category>
</menu>
--%>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Menu HyperLink</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu
id="Menu1"
Runat="server">
<Items>
<asp:MenuItem
Text="Products"
NavigateUrl="http://www.nfex.ru" />
<asp:MenuItem
Text="Services"
NavigateUrl="http://www.nfex.ru">
<asp:MenuItem
Text="Training"
NavigateUrl="http://www.nfex.ru" />
<asp:MenuItem
Text="Consulting"
NavigateUrl="http://www.nfex.ru" />
</asp:MenuItem>
</Items>
</asp:Menu>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<style type="text/css">
.menuLevel1
{
font:40px Arial,Sans-Serif;
}
.menuLevel2
{
font:20px Arial,Sans-Serif;
}
.menuLevel3
{
font:10px Arial,Sans-Serif;
}
</style>
<title>Menu Level Styles</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu
id="Menu1"
Runat="server">
<LevelMenuItemStyles>
<asp:MenuItemStyle CssClass="menuLevel1" />
<asp:MenuItemStyle CssClass="menuLevel2" />
<asp:MenuItemStyle CssClass="menuLevel3" />
</LevelMenuItemStyles>
<Items>
<asp:MenuItem Text="Produce">
<asp:MenuItem Text="Apples" />
<asp:MenuItem Text="Oranges" />
</asp:MenuItem>
<asp:MenuItem Text="Beverages">
<asp:MenuItem Text="Soda">
<asp:MenuItem Text="Coke" />
<asp:MenuItem Text="Pepsi" />
</asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>
</div>
</form>
</body>
</html>
XML based Menu (C#)
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Menu XML</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu
id="Menu1"
DataSourceID="srcMenu"
Runat="server" />
<asp:XmlDataSource
id="srcMenu"
DataFile="Menu.xml"
Runat="server" />
</div>
</form>
</body>
</html>
<%--
<?xml version="1.0" encoding="utf-8" ?>
<menu>
<appetizer>
<soup />
<cheese />
</appetizer>
<entree>
<duck />
<chicken />
</entree>
<dessert>
<cake />
<pie />
</dessert>
</menu>
--%>