That looks like exactly what I'm looking for, if I could get it to work. The value for the case loop, where is that taken from, the aaa and bbb you had up there? I get no errors so I'm not sure where I'm going wrong, probably something wrong in connecting all the parts to eachother. Let me know if you can spot it... (this is just a test I threw together)
Masterpage code:
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal"
StaticDisplayLevels="2">
<Items>
<asp:MenuItem NavigateUrl="0.aspx" Text="New Item" Value="New Item">
<asp:MenuItem NavigateUrl="1.aspx" Text="1" Value="1"></asp:MenuItem>
<asp:MenuItem NavigateUrl="2.aspx" Text="2" Value="2"></asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>
Masterpage Code behind:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Menu1_PreRender(object sender, EventArgs e)
{
if (Menu1.SelectedItem == null)
return;
switch (Menu1.SelectedItem.Value)
{
case "1":
Menu1.StaticSelectedStyle.CssClass = "style1";
break;
case "2":
Menu1.StaticSelectedStyle.CssClass = "style2";
break;
}
}
}
CSS code:
.style1
{
background: url(1.jpg)
}
.style2
{
background: url(2.jpg);
}
-----------------
Cheers
EDIT: I hadn't loaded the event, I have now but Menu1.SelectedItem remains null...
EDIT2: Using a Sitemap to provide the nodes it worked, not if I had static nodes added directly in the menucode, very strange. Thanks for the help...