Dynamic menu style in Menu control
Menu is an asp.net web server control. menu control's DynamicMenuStyle property get a reference to the
MenuItemStyle object that allow us to set the appearance of a dynamic menu. we can set the menu control's dynamic menu style such as
background color, font name, text size, text color, border style, border width etc by using this property.
the DynamicMenuStyle property value type is System.Web.UI.WebControls.SubMenuStyle. this 'SubMenuStyle' represents the style of a dynamic menu. this property has few sub properties. we can set this property value both declaratively in the form Property-Subproperty and programmatically in the form Property.Subproperty (DynamicMenuStyle.BackColor).
the following asp.net c# example code demonstrate us how can we set or change the menu control's dynamic menu style programmatically at run time in an asp.net application.
the DynamicMenuStyle property value type is System.Web.UI.WebControls.SubMenuStyle. this 'SubMenuStyle' represents the style of a dynamic menu. this property has few sub properties. we can set this property value both declaratively in the form Property-Subproperty and programmatically in the form Property.Subproperty (DynamicMenuStyle.BackColor).
the following asp.net c# example code demonstrate us how can we set or change the menu control's dynamic menu style programmatically at run time in an asp.net application.
MenuDynamicMenuStyle.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Menu1.DynamicMenuStyle.BackColor = Color.MistyRose;
}
protected void Button2_Click(object sender, System.EventArgs e)
{
Menu1.DynamicMenuStyle.BackColor = Color.Wheat;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set, change dynamic menu style in Menu control programmatically</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy; font-style:italic;">Menu Example: DynamicMenuStyle</h2>
<asp:SiteMapDataSource
ID="SiteMapDataSource1"
runat="server"
/>
<div style="height:150px">
<asp:Menu
ID="Menu1"
runat="server"
DataSourceID="SiteMapDataSource1"
Font-Bold="true"
ForeColor="PaleVioletRed"
>
</asp:Menu>
</div>
<asp:Button
ID="Button1"
runat="server"
ForeColor="IndianRed"
Text="Chnage DynamicMenuStyle"
Height="45"
OnClick="Button1_Click"
Font-Bold="true"
/>
<asp:Button
ID="Button2"
runat="server"
ForeColor="IndianRed"
Text="Another DynamicMenuStyle"
Height="45"
OnClick="Button2_Click"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.


