More in this section

Forums / Developing with Sitefinity / return main level sitemap nodes

return main level sitemap nodes

3 posts, 0 answered
  1. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    17 Nov 2009
    Link to this post
    I am sure this is a simple thing but I just can not get it right.  I wrote some code to insert an html break into my navigation menu items when there is a blank space or an ampersand to get the menu items to break onto two line in my horizontal nav bar.  What I now need to do is to have this code run only for the main level navigation (not parents in general but only the main level)  items and not for the children (drop downs) beneath the main level naviagtion items. I don't want the drop downs to insert the html break.
    if (e.Item.Text.Contains(" ") || e.Item.Text.Contains("&"))  
            {  
                nPoss = e.Item.Text.IndexOf("&");  
                if (nPoss == -1) //no ampersand then look for space  
                {  
                    nPoss = e.Item.Text.IndexOf(" "); //position of space  
                    if (nPoss > -1) //if there is a space and no ampersand  
                    {  
                        //insert <br /> after nPoss  
                        sText = e.Item.Text.Insert(nPoss, "<br />");  
                        //  sText = Convert.ToString(nPoss) + "space";  
                        e.Item.Text = sText;  
                    }  
                }  
                else //there is an ampersand  
                {  
                    //insert <br /> after nPoss   
                    sText = e.Item.Text.Insert(nPoss + 1, "<br />");  
                    //sText = Convert.ToString(nPoss) + "ampersand";  
                    e.Item.Text = sText;  
                }  
            } 


    I tried things like this below but doesn't work and again need for top level only and I think I am trying to do the parent thing but I think that a parent can also be a child...  :
    if (e.Item.Level.Equals == e.Item.Parent)  
        {  
        //insert code  
        } 

    and this:
    foreach (RadMenuItem item in RadMenu1.Items)  
                if (item.Parent != null)  
                {  
                    //insert code  
                }  
                 

    Thank you in advance! -Laura
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Nov 2009
    Link to this post
    Hello Laura,

    Try using the following line

    CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode;
    if (node != null && e.Item.Level == 0)
    {
     // do something
    }

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    17 Nov 2009
    Link to this post
    Thank Ivan.  Knew it woul be a simple answer!  And it also helped when I put white-space:nowrap in the css for the group items!
Register for webinar
3 posts, 0 answered