This is a migrated thread and some comments may be shown as answers.

Best way to allow for different customizations

1 Answer 45 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Samantha
Top achievements
Rank 1
Samantha asked on 09 Oct 2008, 11:28 PM
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? 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Oct 2008, 07:38 AM
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.
Tags
Menu
Asked by
Samantha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or