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 515163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:35:59+00:00 2026-05-13T07:35:59+00:00

This protected void Page_Load(object sender, EventArgs e) { RadioButtonList1.Items.Add(new ListItem(London,1)); RadioButtonList1.Items.Add(new ListItem(Paris, 2)); }

  • 0

This

protected void Page_Load(object sender, EventArgs e) {
    RadioButtonList1.Items.Add(new ListItem("London","1"));
    RadioButtonList1.Items.Add(new ListItem("Paris", "2"));
}

and this

   <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatLayout="Flow">
   </asp:RadioButtonList></div>

produce HTML something like this

   <input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" />
   <label for="RadioButtonList1_0">London</label>
   <input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" />
   <label for="RadioButtonList1_1">Paris</label>

but what I really want is this, note the class in the <label> tag.

    <input type="radio" name="Event" id="whatever" value="1" /> 
    <label for="London" class="London">London</label> 
    <input type="radio" name="Event" id="whatever" value="2" /> 
    <label for="Paris" class="Paris">Paris</label> 

Can I add a cssClass to the automatically generated <label> tag?

  • 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-05-13T07:36:00+00:00Added an answer on May 13, 2026 at 7:36 am

    You could inherit from RadioButtonList, like shown here or here.

    The last link is probably more in line with what you want.

    You should only need to override the RenderItem method, like so:

    protected override void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
    {
        RadioButton radioButton = new RadioButton();
        radioButton.Page = this.Page;
        radioButton.GroupName = this.UniqueID;
        radioButton.ID = this.ClientID + "_" + repeatIndex.ToString();
        radioButton.Text = this.Items[repeatIndex].Text;            
        radioButton.Attributes["value"] = this.Items[repeatIndex].Value;
        radioButton.Checked = this.Items[repeatIndex].Selected;
        radioButton.TextAlign = this.TextAlign;
        radioButton.AutoPostBack = this.AutoPostBack;
        radioButton.TabIndex = this.TabIndex;
        radioButton.Enabled = this.Enabled;
    
        radioButton.CssClass = InnerCssClass;
        radioButton.Style.Add(HtmlTextWriterStyle.BackgroundColor, this.Items[repeatIndex].Text);
    
        radioButton.RenderControl(writer);
    
        // add new label
        Label radioLabel = new Label();
        radioLabel.Text = this.Items[repeatIndex].Text;
        radioLabel.CssClass = this.Items[repeatIndex].Text;
        radioLabel.AssociatedControlID = this.ClientID + "_" + repeatIndex.ToString();
        radioLabel.RenderControl(writer);
    }
    

    Note, I have not actually compiled above code, but should be enough to guide you in a proper direction 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: protected void Page_Load(object sender, EventArgs e) { nome_Txt.Text = Profile.dados_pessoais.nome; }
In the pageload i populate a dropdownlist like this: protected void Page_Load(object sender, EventArgs
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetLeft.Value = invited.GetInviteCountByWeb().ToString(); HttpCookie
this is the simple code: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)
I have this code protected void Page_Load(object sender, EventArgs e) { DataSet.DestinationsDataTable GetDestinations =
I'm loading a user control programatically like this: protected void Page_Load(object sender, EventArgs e)
I have this code: protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) {
If I write this code protected void Page_Load(object sender, EventArgs e) { Page_Load(sender, e);
I got a question. When I put this code protected void Page_Load(object sender, EventArgs
Look at this code: static int i = 0; protected void Page_Load(object sender, EventArgs

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.