Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:51:54+00:00 2026-06-13T10:51:54+00:00

hi all I have a MenuItem that im dynamically adding childrent to using the

  • 0

hi all I have a MenuItem that im dynamically adding childrent to using the following code

MenuItem c1 = new MenuItem("text","value");
parent.ChildItems.Add(c1);

however I need to add a css class to it at the the same time something like

c1.cssClass = "cssclass";
or 
c1.attributes.Add("Class","cssclass");

does anyone know how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:51:54+00:00Added an answer on June 13, 2026 at 10:51 am

    MenuItem doesn’t have a CSS class property, instead add the class to the parent Menu:

    Menu menu = new Menu();
    menu.CssClass = "myclass";
    

    If you want to dynamically add classes to the menu then try creating a helper method (Extension Methods in C#):

    public static class MenuExtension
    {
        public static void AddCSSClass(this Menu menu, string className)
        {
            // additional code here to tidy / remove duplicates etc.
    
            menu.CssClass = string.Concat(menu.CssClass, " ", className);
        }
    }
    

    Since our Menu renders a UL you can then use CSS selectors to cascade the style to all child LI elements:

    .myclass > li {
        // your attributes
    }
    

    Or alternatively, specific LI elements (things like nth-child etc are only supported in CSS 3.0):

    .myclass > li:first-child {
        // your attributes
    }
    
    .myclass > li:nth-child(1) {
        // your attributes
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need all new MenuItem models to have menu attribute from parent collection. Here
I have the following code in my page that creates a new Dojo/Dijit TabContainer.
I have about 8 entities that all have a one to one relationship with
I have three classes that all have a static function called 'create'. I would
I have a database with Points of Interest that all have an address. I
i have hundreds of [mostly different] files in many different directories that all have
I have 3 similar tables, that would all have the same enum type field.
I have a menu with a 'Windows' list that contains all mdi children thanks
I have a list of tab items that have views dynamically added to them.
I have the following database design for a menuItem table Id PId MenuLink ---

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.