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

Forums / Developing with Sitefinity / Add icons to SiteMenu

Add icons to SiteMenu

15 posts, 0 answered
  1. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    07 Jul 2009
    Link to this post
    I was wondering what the easiest to maintain method would be to add icons to the SiteMenu entries (one for each page)?  Since the control is dynamically populated from the DB, I'm not really sure where the best place is to add a property for the icon url, nor how to attach this icon to the RadMenu entries.  Is there already a means of associating icons with pages in the RadMenu control built into Sitefinity?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Jul 2009
    Link to this post
    Hi Kevin,

    The easiest way is to modify ItemDataBound event of the RadMenu.
    Below is a sample code:

     public void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e) 
        { 
     
            CmsSiteMapNode imageNode = e.Item.DataItem as CmsSiteMapNode; 
            if (imageNode != null
            { 
                switch (e.Item.Text) 
                { 
                    case "item1"
                        e.Item.ImageUrl = "~/Images/" + e.Item.Text + ".gif"
                        break
                    case "item2"
                        e.Item.ImageUrl = "~/Images/" + e.Item.Text + ".gif"
                        break
                } 
                
            } 
            .... 
                   ..... 
     } 
     

    Basically we have a folder called images and there gif image for each of our items. Each image is named to the item text.

    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.
  3. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    07 Jul 2009
    Link to this post
    Ivan:

    Thanks for the reply.  It works fine with the adjustments you suggested (though I should probably make a new copy of SiteMap alltogether since I try to keep all my modified files in a ~/Custom folder to make upgrading easier).

    Kevin.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Jul 2009
    Link to this post
    Hello Kevin,

    You can get SiteMenu control from Sitefinity/UserControls/Navigation35, extend the control and put it under a new folder. Thus, you will not forget to copy your custom folder when upgrading.

    Sincerely yours,
    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. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    07 Jul 2009
    Link to this post
    Just in case anyone else comes across this post via Google, etc., this is what I ended up implementing:

    1         CmsSiteMapNode imageNode = e.Item.DataItem as CmsSiteMapNode;  
    2         if (imageNode != null)  
    3         {  
    4           // Check if new  
    5           TimeSpan difference = DateTime.Now.Subtract(imageNode.GetCmsPage().DateCreated);  
    6           if (difference.Days < 14)  
    7           {  
    8             // Page is less than two weeks old ... signal it as new  
    9             e.Item.ImageUrl = "~/Images/Menu/New.png";  
    10           }  
    11           // Set individual icons  
    12           switch (e.Item.Text)  
    13           {  
    14             case "Store":  
    15               e.Item.ImageUrl = "~/Images/Menu/" + e.Item.Text.Replace(" ""_") + ".png";  
    16               e.Item.Text = string.Format("<strong>&nbsp;{0}</strong>", e.Item.Text);  
    17               break;  
    18             case "Shopping Cart":  
    19               e.Item.ImageUrl = "~/Images/Menu/" + e.Item.Text.Replace(" ""_") + ".png";  
    20               break;  
    21           }  
    22         }  
    23  
     It adds a 'new' icon to any page less than 14 days old, and in the case of 'Store' and 'Shopping Cart' adds a specific icon.  I don't really like hard-coding this kind of stuff into C#, but it works, and it at least a good start until I make the time to develop a less intrusive solution.  I'll also need to cache this, since it will likely be fairly heavy to call .GetCmsPage() for every menu item.

    Thanks again for your help on this Ivan!

    Kevin.
  6. Richa
    Richa avatar
    69 posts
    Registered:
    04 Jun 2009
    22 Jul 2009
    Link to this post
    I tried to use itemdatabound in my master page on which sitemenu resides inside a contentplaceholder...
    i got the error:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0234: The type or namespace name 'WebControls' does not exist in the namespace 'Telerik' (are you missing an assembly reference?)

    Source Error:

    Line 1:  using System;
    Line 2:  using System.Collections.Generic;
    Line 3: using Telerik.WebControls;Line 4:  using System.Web;
    Line 5:  using System.Web.UI;

    I also did not find RadMenu.Net2.dll in my installation folder...

    What else can be done to get rid of this error?
  7. Richa
    Richa avatar
    69 posts
    Registered:
    04 Jun 2009
    22 Jul 2009
    Link to this post

    It worked after i added:

     

    using Telerik.Web.UI;


    Thanks anyways...
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Jul 2009
    Link to this post
    Hello Richa,

    It seems that you are using an old version of RadControls. Please check whether you have Telerik.WebControls assemble in your bin. The error is not thrown by the RadMenu control.

    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.
  9. Richa
    Richa avatar
    69 posts
    Registered:
    04 Jun 2009
    22 Jul 2009
    Link to this post
    Thanks for your prompt reply.

    It not giving nay compilation error but it's not producing results!! :(
    do i have to register the event RadMenu1_ItemDataBound somewhere?

    i did not find any place to do this when i try to edit the sitemenu properties on the master page!!
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Jul 2009
    Link to this post
    Hi Richa,

    You can subscribe for RadMenu's ItemDataBound evetn on PageLoad.

    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.
  11. Richa
    Richa avatar
    69 posts
    Registered:
    04 Jun 2009
    22 Jul 2009
    Link to this post
    gives an error:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'RadMenu1' does not exist in the current context

    Source Error:

    Line 13: protected void Page_Load(object sender, EventArgs e) 
    Line 14: {
    Line 15: RadMenu1.ItemDataBound += RadMenu1_ItemDataBound;

    Line 16: }
    Line 17:

    the menu's id is RadMenu1
  12. Richa
    Richa avatar
    69 posts
    Registered:
    04 Jun 2009
    24 Jul 2009
    Link to this post
    anybody?? any help?? any suggestions??
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Jul 2009
    Link to this post
    Hi Richa,

    Try using "this". Below is a sample code:

     this.RadMenu1.ItemDataBound +=new RadMenuEventHandler(RadMenu1_ItemDataBound); 

    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.
  14. Richa
    Richa avatar
    69 posts
    Registered:
    04 Jun 2009
    24 Jul 2009
    Link to this post
    Nope doesnt work:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1061: 'Home' does not contain a definition for 'RadMenu1' and no extension method 'RadMenu1' accepting a first argument of type 'Home' could be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 13:     protected void Page_Load(object sender, EventArgs e)
    Line 14:     {
    Line 15: this.RadMenu1.ItemDataBound +=new RadMenuEventHandler(RadMenu1_ItemDataBound); Line 16:     }
    Line 17:     
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Jul 2009
    Link to this post
    Hi Richa,

    Please send me the control template and its code behind. If there is control with this id you should not get the error. What intellisense shows when you try to subscribe for the event?

    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.
Register for webinar
15 posts, 0 answered