Best way to allow for different customizations

2 posts, 1 answers
  1. Samantha
    Samantha avatar
    50 posts
    Member since:
    May 2008

    Posted 09 Oct 2008 Link to this post

    I would like to create a menu that is bound to a sitemap.  I would like to be able to have some menu items styled differently than others.  Some of the customizations I am interested in are:

    One root menu item with a different background color than all the others.

    One root menu item's children to all be prefixed with an image.

    One root menu item as an image.

    The rest of the root menu items and children can be formatted the same way.

    What is the best way to code this so that I can still bind everything dynamically from the sitemap? 
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Oct 2008 Link to this post

    Hello Samantha,

    You can try out the following code to achieve the required scenario. You can check for the text of the item and then make modifications as required.
    cs:
    protected void RadMenu1_PreRender(object sender, EventArgs e) 
        { 
          //One root menu item with a different background color  
            RadMenu1.Items[0].BackColor = System.Drawing.Color.Violet; 
     
          //One root menu item as an image 
           foreach (RadMenuItem item in RadMenu1.Items) 
            { 
                if (item.Text == "Menu1") 
                { 
                    item.Controls.Clear(); 
                    Image img = new Image(); 
                    img.ID = "Image1"
                    img.ImageUrl = "~/images/Image1.gif"
                    item.Controls.Add(img); 
                } 
     
                
               //One root menu item's children to all be prefixed with an image 
                if (item.Text == "Menu2") 
                { 
                  foreach(RadMenuItem subitem in item.Items) 
                    { 
                        subitem.ImageUrl = "~/images/Image2.gif"
                    }                 
                } 
            }              
        } 

    Thanks
    Princy.
Back to Top