具有导航栏样式的Asp.net菜单

时间:2018-09-11 12:43:31

标签: css asp.net menu

我想在asp.menu中使用引导菜单样式,但是我的所有尝试都无法正常工作。

我要使用的菜单是

 <nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark fixed-top">
  <div class="container">
    <a class="navbar-brand" href="Default.aspx">web name </a>
    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item">
          <a class="nav-link" href="aboutus.aspx">aboutus</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="contact.html">contact</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownPortfolio" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Portfolio
          </a>
          <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownPortfolio">
            <a class="dropdown-item" href="portfolio-1-col.html">1 Column Portfolio</a>
            <a class="dropdown-item" href="portfolio-2-col.html">2 Column Portfolio</a>
            <a class="dropdown-item" href="portfolio-3-col.html">3 Column Portfolio</a>
            <a class="dropdown-item" href="portfolio-4-col.html">4 Column Portfolio</a>
            <a class="dropdown-item" href="portfolio-item.html">Single Portfolio Item</a>
          </div>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownBlog" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Blog
          </a>
          <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownBlog">
            <a class="dropdown-item" href="blog-home-1.html">Blog Home 1</a>
            <a class="dropdown-item" href="blog-home-2.html">Blog Home 2</a>
            <a class="dropdown-item" href="blog-post.html">Blog Post</a>
          </div>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownBlog5" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Other Pages
          </a>
          <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownBlog">
            <a class="dropdown-item" href="full-width.html">Full Width Page</a>
            <a class="dropdown-item" href="sidebar.html">Sidebar Page</a>
            <a class="dropdown-item" href="faq.html">FAQ</a>
            <a class="dropdown-item" href="404.html">404</a>
            <a class="dropdown-item" href="pricing.html">Pricing Table</a>
          </div>
        </li>
      </ul>
    </div>
  </div>
</nav>

以上菜单正常,可以正常使用Example

我要使用的asp菜单是

 <asp:Menu ID="Menu2" runat="server" Orientation="Horizontal" RenderingMode="List" DataSourceID="SiteMapDataSource2">
         </asp:Menu>

我必须尝试在asp.net菜单中使用引导程序,如下所示: 在div <div class="collapse navbar-collapse" id="navbarResponsive">

 <asp:Menu ID="Menu51" 
    runat="server" 
    Orientation="Horizontal" 
    StaticDisplayLevels="1"
    StaticEnableDefaultPopOutImage="False"
   DataSourceID="SiteMapDataSource2"
    MaximumDynamicDisplayLevels="10" 
    EnableViewState="false"


    StaticMenuStyle-CssClass="navbar-nav ml-auto" 
    StaticMenuItemStyle-CssClass="nav-link"
    StaticSelectedStyle-CssClass="active"

    DynamicMenuStyle-CssClass="dropdown-menu dropdown-menu-right show" 
    DynamicMenuItemStyle-CssClass="dropdown-item"


    IncludeStyleBlock="false" 
    SkipLinkText=""
    RenderingMode="List">


</asp:Menu>

现在的问题是,当我运行我的网页时,菜单没有采用所有样式,您可以对其进行检查,您会发现li标记未采用类名称,所以云上有人在帮助我吗?

1 个答案:

答案 0 :(得分:0)

其他网站上的一个人给我一个巧妙的解决方案,他使用asp:Repeater而不是asp:Menu,所以我在转发器中调用了站点地图,效果很好,

<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark fixed-top">
  <div class="container">
    <a class="navbar-brand" href="Default.aspx">web name </a>
    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
                            <asp:Repeater runat="server" ID="menu1" DataSourceID="SiteMapDataSource2">
                                <ItemTemplate>
                                    <li class='<%# ((SiteMapNode) Container.DataItem).ChildNodes.Count == 0 ? "nav-item" : "nav-item dropdown" %>'>
                                        <asp:HyperLink CssClass="nav-link" runat="server" Visible='<%# ((SiteMapNode) Container.DataItem).ChildNodes.Count == 0 ? true : false %>' NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
                                        <asp:HyperLink CssClass="nav-link dropdown-toggle" ID="navbarDropdownPortfolio" Visible='<%# ((SiteMapNode) Container.DataItem).ChildNodes.Count == 0 ? false : true %>' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" runat="server" NavigateUrl='#'><%# Eval("Title") %></asp:HyperLink>
                                        <asp:Repeater runat="server" DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>
                                            <HeaderTemplate>
                                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownPortfolio">
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:HyperLink CssClass="dropdown-item" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                </div>
                                            </FooterTemplate>
                                        </asp:Repeater>
                                    </li>
                                </ItemTemplate>
                            </asp:Repeater>
       </ul>
    </div>
  </div>
</nav>

,这项工作非常好 谢谢大家