1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Question about CmsPage

Question about CmsPage

10 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    23 Jun 2009
    Link to this post
    Hi all,

    I'm doing some coding on the DataBound event of the RadMenu. I'm trying to set the CssClass property of the menu items. If I loop through the menu I can access the .Text property, but I actualy need the Name of the page. I know that is a property of the CmsPage or IPage, but I can't figure out how to get there? I suppose with help of the CmsManager, but then I like to cast this to the right menu item.

    1 protected void RadMenu1_DataBound(object sender, EventArgs e) 
    2     { 
    3         CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode; 
    4          
    5         foreach (RadMenuItem item in this.RadMenu1.Items) 
    6         { 
    7             try 
    8             { 
    9                 string newValue = string.Empty; 
    10                  
    11                 if (currentNode != null
    12                 { 
    13                     switch (item.Value) 
    14                     { 
    15                         case "Home"
    16                             newValue = "Home"
    17                             break
    18                         case "Over ons"
    19                             newValue = "AboutUs"
    20                             break
    21                         case "Diensten"
    22                             newValue = "Services"
    23                             break
    24                         case "Portfolio"
    25                             newValue = "Portfolio"
    26                             break
    27                         case "Contact"
    28                             newValue = "Contact"
    29                             break
    30                     } 
    31  
    32                     item.CssClass = newValue; 
    33                     if (currentNode.Url == item.NavigateUrl) 
    34                         item.CssClass = newValue + "On"
    35                 } 
    36             } 
    37             catch (Exception ex) 
    38             { 
    39                 throw ex; 
    40             } 
    41         } 

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Jun 2009
    Link to this post
    Hello Daniel,

    Please give a try to the code below:

       protected void Page_Load(object sender, EventArgs e) 
        { 
            RadMenu1.DataBind(); 
            IList<RadMenuItem> items = RadMenu1.GetAllItems(); 
            foreach (RadMenuItem item in items) 
            if (item != null
            { 
                switch (item.Text) 
                { 
                    case "red"
                        item.CssClass = "RedItem"
                        break
                    case "blue"
                        item.Text = "BlueItem"
                        break
                } 
            } 
        } 


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    23 Jun 2009
    Link to this post
    But is the item.Text corresponding with the Name property of the CmsPage?

    http://www.sitefinity.com/help/developer-manual/telerik.cms.data-telerik.cms.data.pagebase-name.html

    I don't want to have a case statement based on the text of a menu item.

    Daniel
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Jun 2009
    Link to this post
    Hello Daniel,

    The Text of the RadMenu item comes form the Page Label. In Sitefinity the RadMenu is bounded to the SiteMapDataSource, so that it depends on what you have entered for the page label.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    23 Jun 2009
    Link to this post
    Hmm... I don't get it.
    Maybe I'm not so clear...

    I have copied the SiteMenu control and created a CustomSiteMenu control which acts almost the same as the buildin one.

    I have a page for example:

    Page Name: AboutUs
    Menu Label: Over ons

    At this point, wether I use your solution, or my own, I always get the Text value. How can I get the 'Page Name' for each menu item, so that in case of a multilangual site, I do not have to depent on the Menu Label.

    I hope it is clear what I mean?

    Daniel
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Jun 2009
    Link to this post
    Hi Daniel,

    The text of the RadMenu item is set to the Page MenuName( Label in the admin interface). Unfortunately I cannot give you a solution for changing the item text to the page name, since this is set into CmsSiteMapNode constructior.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    23 Jun 2009
    Link to this post
    I don't want to change the text, but I just want to read out what the pagename is? I'd like to get the corresponding CmsPage and read out the name (Page Name in de admin section).

    Well, I will try some other things.

    Thanks,
    Daniel
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Jun 2009
    Link to this post
    Hi Daniel,

    The sample code below will return the current page name

                CmsSiteMapNode cmsPage = e.Item.DataItem as CmsSiteMapNode; 
            ICmsPage page = cmsPage as ICmsPage; 
            CmsManager manager = new CmsManager(); 
            IList listofPages = manager.GetPages(); 
            foreach (ICmsPage p in listofPages) 
            { 
                IList<RadMenuItem> items = RadMenu1.GetAllItems(); 
                foreach (RadMenuItem item in items) 
                    if (item != null && item.Text.Equals("RadMenuItem")) 
                    { 
                        ICmsPage mypage = manager.GetPage(p.ID) as ICmsPage; 
                        Response.Write(mypage.Name.ToString()); 
                    } 
             } 


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    23 Jun 2009
    Link to this post
    Ah right! That was exactly what I needed. I knew it was possible, but I didn't know where to start from. Thanks! (for your patience)

    Daniel
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Jun 2009
    Link to this post
    Hi Daniel,

    Let us know if there is anything else that we can do for you.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
10 posts, 0 answered