locked
ASP.net Menu RRS feed

  • Question

  • User-49671077 posted

    Can someone help me how how to add sub menu under Home button into the following code:

    Home >

                 Item >

                               Item 1

                               Item 2

    About

    Contant

    Thanks

    ASP.net code:

    </div><div class="Menu">
    <ul><%= RenderMenu() %></ul>

    C# code:

     protected string RenderMenu()
        {
            var result = new StringBuilder();
            RenderMenuItem("Home", "default.aspx", result);
            RenderMenuItem("About", "about.aspx", result);
    RenderMenuItem("Contant", "contant.aspx", result); return result.ToString(); } void RenderMenuItem(string title, string address, StringBuilder output) { output.AppendFormat("<li><a href=\"{0}\" ", address); var requestUrl = HttpContext.Current.Request.Url; if (requestUrl.Segments[requestUrl.Segments.Length - 1].Equals(address, StringComparison.OrdinalIgnoreCase)) // If the requested address is this menu item. output.Append("class=\"ActiveMenuButton\""); else output.Append("class=\"MenuButton\""); output.AppendFormat("><span>{0}</span></a></li> ", title); }

    Tuesday, December 18, 2018 5:47 PM

All replies

  • User-1174608757 posted

    Hi kafsar,

       According to your description,I suggest you to use TreeView control in Webform. It is no suggested to  write html codes in code behind.

    Best Regards 

    WeiZhang

    Wednesday, December 19, 2018 6:57 AM
  • User379720387 posted

    Do it all client side with bootstrap. Much easier.

    getbootstrap.com

    https://getbootstrap.com/docs/3.3/components/#dropdowns

    Wednesday, December 19, 2018 10:33 PM
  • User-2054057000 posted

    The RenderMenuItem() is not made to include sub menus. You have to rewrite is completely to include the process of adding sub menus.

    Thursday, December 20, 2018 12:39 PM