More in this section

Forums / Developing with Sitefinity / RadMenu ItemDataBound CssClass not working as expected

RadMenu ItemDataBound CssClass not working as expected

3 posts, 0 answered
  1. Henry
    Henry avatar
    2 posts
    Registered:
    16 Sep 2008
    27 May 2009
    Link to this post
    Hi,

    I've set up a RadMenu control (vertical flow) and assigned a unique CssClass via the ItemDataBound method... example below:
    protected void RadMenu1_ItemDataBound(object sender, Telerik.Web.UI.RadMenuEventArgs e)  
    {  
     
            String styleName = e.Item.Text.Replace(" ", "");  
     
            e.Item.CssClass = styleName;  
     
    }  
     

    Everything looks correct when I view the page from the starting page (Home), but when I click on other section links, the items above the selected link/section seem to lose their CssClass assignment so only the selected link and links following are assigned their correct style.

    Why aren't all the menu items styled appropriately regardless of what link/section is selected?

    Thanks,
    Henry
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    29 May 2009
    Link to this post
    Hello Henry,

    To solve the issue you need to move the code for setting the CssClass property to Page_Load method like this:

    protected void Page_Load(object sender, EventArgs e) 
        { 
            RadMenu1.DataBind(); 
     
            foreach (RadMenuItem item in RadMenu1.GetAllItems()) 
            { 
                String styleName = item.Text.Replace(" """); 
                item.CssClass = styleName; 
            } 
        } 

    Let us know if this helps.

    Kind regards,
    Pepi
    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. Henry
    Henry avatar
    2 posts
    Registered:
    16 Sep 2008
    31 Jul 2009
    Link to this post
    Sorry for the late response, but yes this worked like a charm.

    Thanks!
Register for webinar
3 posts, 0 answered