我正在为菜单使用站点地图导航。页面导航对我来说工作正常,但父菜单在选择子菜单项时没有突出显示。 我写的代码在下面提到-
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
<asp:Menu ID="Menu" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal"
OnMenuItemDataBound="OnMenuItemDataBound">
<StaticMenuStyle BorderStyle="None" />
<staticselectedstyle backcolor="Green" borderstyle="Solid" bordercolor="Black" borderwidth="1"/>
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" BorderStyle="Solid"
BorderColor="White" BorderWidth="1px" />
<DynamicHoverStyle BackColor="#5E2433" ForeColor="White" />
<DynamicMenuStyle BorderColor="#666666" Width="155px" BackColor="#EFEDED" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<DynamicMenuItemStyle Width="155px" BorderColor="White" BorderStyle="Solid" BorderWidth="1px"
HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#5E2433" ForeColor="White" />
</asp:Menu>
在master.cs页面代码是-
protected void OnMenuItemDataBound(object sender, MenuEventArgs e)
{
if (SiteMap.CurrentNode != null)
{
if (e.Item.Text == SiteMap.CurrentNode.Title)
{
if (e.Item.Parent != null)
{
e.Item.Parent.Selected = true;
}
else
{
e.Item.Selected = true;
}
}
}
}
站点地图就像-
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="" description="">
<siteMapNode url="" title="EMPLOYEES" description="Employees Page">
<siteMapNode url ="" title="New Employee" description=""></siteMapNode>
<siteMapNode url ="" title="Edit Details" description=""></siteMapNode>
<siteMapNode url ="" title="Calender" description=""></siteMapNode>
<siteMapNode url ="employees/Benefits.aspx" title="Benefits" description="">
<siteMapNode url ="employees/Vehicle.aspx" title="Vehicle" description=""></siteMapNode>
<siteMapNode url ="employees/Loan.aspx" title="Loan" description=""></siteMapNode>
<siteMapNode url ="" title="Accomodation" description=""></siteMapNode>
<siteMapNode url ="" title="Medical Insuarance" description="">
<siteMapNode url ="" title="Annual" description=""></siteMapNode>
<siteMapNode url ="" title="One-Off" description=""></siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
我已尝试但无法在选择子菜单项时突出显示父菜单。 任何帮助将不胜感激。
最佳答案
您的代码是正确的。显然,代码只将“选定”类分配给选择菜单项。您必须编写自己的 CSS 来设置所选元素的样式。除此之外,代码是正确的。
#Menu1 ul li a.selected{
border:1px solid blue;
background-color:blue !important;
color:white;
}
您的代码实际上帮助我解决了“选择”问题:)
关于css - ASP.Net 菜单控件在选择子菜单项时不突出显示父菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38844491/