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

Cant add MenuItems programmincally

4 Answers 57 Views
Menu
This is a migrated thread and some comments may be shown as answers.
John Giblin
Top achievements
Rank 1
John Giblin asked on 07 Oct 2009, 04:48 PM
I have tried to add the menu items programmically as show below.  For some reason the separator is not being added.  It works fine if I dont do it programmically. any idea??


RadMenuItem radmenuitem;
RadMenuItem radsepmenuitem;
SiteMapNode RootNode = SiteMap.RootNode;


        for (int i = 0; i < RootNode.ChildNodes.Count; i++)
        {
            // Add Menu Item
            radmenuitem = new RadMenuItem(RootNode.ChildNodes[i].Title, RootNode.ChildNodes[i].Url);
            RadMenu1.Items.Add(radmenuitem);
            // Seperator
            radsepmenuitem = new RadMenuItem("Separator");
            radsepmenuitem.IsSeparator = true;
            radsepmenuitem.CssClass = "p";
            RadMenu1.Items.Add(radsepmenuitem);
            
            // Add Child Menus
            if (RootNode.ChildNodes[i].HasChildNodes)
                PopulateChildNode(RootNode.ChildNodes[i].ChildNodes, radmenuitem);
      }

4 Answers, 1 is accepted

Sort by
0
John Giblin
Top achievements
Rank 1
answered on 08 Oct 2009, 12:36 AM
here is the weird thing. When I do a postback, I do see the separators. 

0
Vesko
Top achievements
Rank 2
answered on 08 Oct 2009, 02:49 PM
What happens if you remove the CssClass property? What exactly does the "p" css class?
Maybe it is a caching issue - can you try with another browser?

Also, does it happen if you do not use SiteMapDataSource?
I tried this and it worked like a charm:

    protected void Page_Load(object sender, EventArgs e) 
    { 
        RadMenuItem radmenuitem; 
        RadMenuItem radsepmenuitem; 
 
        for (int i = 0; i < 5; i++) 
        { 
            // Add Menu Item 
            radmenuitem = new RadMenuItem("aaa"); 
            RadMenu1.Items.Add(radmenuitem); 
            // Seperator 
            radsepmenuitem = new RadMenuItem("Separator"); 
            radsepmenuitem.IsSeparator = true
            RadMenu1.Items.Add(radsepmenuitem); 
        } 
    } 




0
John Giblin
Top achievements
Rank 1
answered on 08 Oct 2009, 09:42 PM
This was really stupid.  when I used that code I also put the DataSourceId  in the RadMenu for the asp:SiteMapDataSource. So the datasource was overriding my code.



0
Vesko
Top achievements
Rank 2
answered on 09 Oct 2009, 01:53 PM
Glad that it works now
Tags
Menu
Asked by
John Giblin
Top achievements
Rank 1
Answers by
John Giblin
Top achievements
Rank 1
Vesko
Top achievements
Rank 2
Share this question
or