Cant add MenuItems programmincally

5 posts, 0 answers
  1. John Giblin
    John Giblin avatar
    155 posts
    Member since:
    Jan 2006

    Posted 07 Oct 2009 Link to this post

    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);
          }

  2. John Giblin
    John Giblin avatar
    155 posts
    Member since:
    Jan 2006

    Posted 07 Oct 2009 Link to this post

    here is the weird thing. When I do a postback, I do see the separators. 

  3. Vesko
    Vesko avatar
    122 posts
    Member since:
    Mar 2009

    Posted 08 Oct 2009 Link to this post

    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); 
            } 
        } 




  4. John Giblin
    John Giblin avatar
    155 posts
    Member since:
    Jan 2006

    Posted 08 Oct 2009 Link to this post

    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.



  5. Vesko
    Vesko avatar
    122 posts
    Member since:
    Mar 2009

    Posted 09 Oct 2009 Link to this post

    Glad that it works now
Back to Top