how to custome widget MainMenu level 3

Posted by Community Admin on 03-Aug-2018 09:16

how to custome widget MainMenu level 3

All Replies

Posted by Community Admin on 31-Jul-2017 00:00

Hai...

I have problems with level 3 mainmenu

Following mainmenu.ascx script :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web;

internal class NodeInfo

    public string Url get; set;
    public string Title get; set;
    public bool IsCurrent get; set;

    public List<NodeInfo> ChildNodes get; set;

    public NodeInfo()
   
        ChildNodes = new List<NodeInfo>();
   


public partial class UserControls_MainMenu : System.Web.UI.UserControl

    private List<NodeInfo> _nodes = new List<NodeInfo>();
    protected  void Page_PreRender()
   
        _nodes.Clear();
        if(SiteMap.RootNode.HasChildNodes)
       
            foreach(SiteMapNode node in SiteMap.RootNode.ChildNodes)
           
                NodeInfo nodeInfo = ProcessNode(node);
                if (nodeInfo != null)
               
                    if (node.HasChildNodes)
                   
                        foreach (SiteMapNode childNode in node.ChildNodes)
                       
                            NodeInfo childNodeInfo = ProcessNode(childNode);

                            if (childNodeInfo != null)
                           
                                nodeInfo.ChildNodes.Add(childNodeInfo);

if (childNode.HasChildNodes)

foreach (SiteMapNode childNode2 in childNode.ChildNodes)

NodeInfo childNodeInfo2 = ProcessNode(childNode2);

if (childNodeInfo2 != null)

childNodeInfo.ChildNodes.Add(childNodeInfo2);



                           
                       
                   


                    _nodes.Add(nodeInfo);
               

                if (node.Title == "news" && Request.RawUrl.Contains("article"))
               
                    _nodes.Last().IsCurrent = true;
               
           
       
   

    private NodeInfo ProcessNode(SiteMapNode node)
   
        if ((node is PageSiteNode) && (node as PageSiteNode).ShowInNavigation)
       
            bool nodeCurrent = false;
            if (SiteMap.CurrentNode != null)
           
                if (node.Title == SiteMap.CurrentNode.Title) nodeCurrent = true;
                else if (node.HasChildNodes)
               
                    foreach (SiteMapNode childNode in node.ChildNodes)
                   
                        if (childNode.Title == SiteMap.CurrentNode.Title) nodeCurrent = true;
                        else if (childNode.HasChildNodes)
                       
                            foreach (SiteMapNode childNode2 in childNode.ChildNodes)
                           
                                if (childNode2.Title == SiteMap.CurrentNode.Title)
                                    nodeCurrent = true;
                           
                       
                   
               
           

            NodeInfo result = new NodeInfo()
           
                Title = node.Title,
                Url = ResolveClientUrl(node.Url),
                IsCurrent = nodeCurrent
            ;

            return result;

       

        return null;
   

    protected override void  Render(HtmlTextWriter writer)
   
writer.Write("<div class=\"menu-button\">MENU</div>");
        writer.Write("<ul data-breakpoint=\"959\" class=\"flexnav\">");
        string aFormat = "<li class=\"1\"><a href=\"0\"><span>2</span></a>";
        string childFormat = "<li><a href=\"0\"><span>1</span></a>";

        for(int i=0;i<_nodes.Count;i++)
       
if (i==0)

if (_nodes[i].IsCurrent)
writer.Write(string.Format(aFormat, _nodes[i].Url, "current_page_item first", _nodes[i].Title));
else
writer.Write(string.Format(aFormat, _nodes[i].Url, "first", _nodes[i].Title));

else
if (_nodes[i].IsCurrent)
writer.Write(string.Format(aFormat, _nodes[i].Url, "current_page_item", _nodes[i].Title));
else
writer.Write(string.Format(aFormat, _nodes[i].Url, string.Empty, _nodes[i].Title));



            if(_nodes[i].ChildNodes.Count > 0)
           
                writer.Write("<ul>");

for(int j=0;j<_nodes[i].ChildNodes.Count;j++)

writer.Write(string.Format(childFormat, _nodes[i].ChildNodes[j].Url, _nodes[i].ChildNodes[j].Title));

if(_nodes[i].ChildNodes[j].ChildNodes.Count > 0)

writer.Write("<ul>");
foreach (NodeInfo childNode in _nodes[i].ChildNodes[j].ChildNodes)

writer.Write(string.Format(childFormat, childNode.Url, childNode.Title));
writer.Write("</li>");

writer.Write("</ul>");


writer.Write("</li>");


                writer.Write("</ul>");
           


            writer.Write("</li>");
            
       

        writer.Write("</ul>");
writer.Write("<div class=\"clr\"></div>");
   

    protected void Page_Load(object sender, EventArgs e)
   

   


How to level 3 menu can display?

Thanks,

Mamat

 

 

This thread is closed