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

  • SEARCH
  • Home
  • 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 6236317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:49:55+00:00 2026-05-24T10:49:55+00:00

I have a large RadioButtonList (about 20 items) and need to check which one

  • 0

I have a large RadioButtonList (about 20 items) and need to check which one was selected in order to return that value with the submitted email (it’s an email form).

Right now I’m running a large If-Else-If loop to parse through each RadioButton to find out which one was selected:

           if (PriMsg_AP_1.Checked)
            {
                message.Body += "<b>Primary Message:</b> " + PriMsg_AP_1.Text;
            }
            else if (PriMsg_AP_2.Checked)
            {
                message.Body += "<b>Primary Message:</b> " + PriMsg_AP_2.Text;
            }
            else if (PriMsg_Devices_1.Checked)
            {
                message.Body += "<b>Primary Message:</b> " + PriMsg_Devices_1.Text;
            }
            else if (PriMsg_SMB_1.Checked)
            {
                message.Body += "<b>Primary Message:</b> " + PriMsg_SMB_1.Text;
            }
            else if (PriMsg_SMB_2.Checked)
            {
                message.Body += "<b>Primary Message:</b> " + PriMsg_SMB_2.Text;
            }
            else if (PriMsg_SMB_3.Checked)
            {
                message.Body += "<b>Primary Message:</b> " + PriMsg_SMB_3.Text;
            }
            else if (PriMsg_Vertical_1.Checked)
            {
                message.Body += "<b>Primary Message:</b> " + PriMsg_Vertical_1.Text;
            }
            else if (PriMsg_Vertical_2.Checked)
            {
                message.Body += "<b>Primary Message:</b> " + PriMsg_Vertical_2.Text;
            }

etc.

As you can see it’s pretty long and to me I would think there is an easier way to parse this list. Like running everything through a For loop? But not sure how to do that since each RadioButton has a different name…

Some caveats: The list is broken under multiple categories so not all RadioButtons are in one screen so I have the whole list tied with a GroupName so that the user can only select one item.

Thoughts? Suggestions?

I’m working in ASP.NET on this project.

~Allen

Edit: I’m using individual RadioButtons and tying them together with a GroupName. Not using a RadioButtonList. Sorry about the confusion.

<asp:RadioButton ID="PriMsg_AP_1" GroupName="PriMsg" runat="server" text="Promo 1" CssClass="radiobutton" />
  • 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-24T10:49:56+00:00Added an answer on May 24, 2026 at 10:49 am

    You could use the conditional operator, which would make the code a lot shorter:

    message.Body += "<b>Primary Message:</b> " +
      PriMsg_AP_1.Checked ? PriMsg_AP_1.Text :
      PriMsg_AP_2.Checked ? PriMsg_AP_2.Text :
      PriMsg_Devices_1.Checked ? PriMsg_Devices_1.Text :
      PriMsg_SMB_1.Checked ? PriMsg_SMB_1.Text :
      PriMsg_SMB_2.Checked ? PriMsg_SMB_2.Text :
      PriMsg_SMB_3.Checked ? PriMsg_SMB_3.Text :
      PriMsg_Vertical_1.Checked ? PriMsg_Vertical_1.Text :
      PriMsg_Vertical_2.Checked ? PriMsg_Vertical_2.Text :
      "No message";
    

    Another alternative would be to put all the radio buttons in a collection so that you can loop through them:

    RadioButton[] radios = new RadioButton[] {
      PriMsg_AP_1, PriMsg_AP_2, PriMsg_Devices_1,
      PriMsg_SMB_1, PriMsg_SMB_2, PriMsg_SMB_3,
      PriMsg_Vertical_1, PriMsg_Vertical_2
    };
    foreach (RadioButton radio in radios) {
      if (radio.Checked) {
        message.Body += "<b>Primary Message:</b> " + radio.Text;
        break;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have large log files which contains timestamps every one second.what I need is
I have large amounts of scientific data that I need to store (150 TB+
I have large text files upon which all kinds of operations need to be
I have large URL(without spaces) in one of my Table(html table element) cell which
I have large json data which is contains hundreds thousands elements, now i need
I have large data files stored in S3 that I need to analyze. Each
I have large batches of XHTML files that are manually updated. During the review
I'm developing a website in PHP and I have large JS files that I
Interpolating Large Datasets I have a large data set of about 0.5million records representing
I have a large codebase that targetted Flash 7, with a lot of AS2

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.