Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a better way to read a RadioButtonList than If-Else-If loops?
    primarykey
    data
    text
    <p>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).</p> <p>Right now I'm running a large If-Else-If loop to parse through each RadioButton to find out which one was selected:</p> <pre><code> if (PriMsg_AP_1.Checked) { message.Body += "&lt;b&gt;Primary Message:&lt;/b&gt; " + PriMsg_AP_1.Text; } else if (PriMsg_AP_2.Checked) { message.Body += "&lt;b&gt;Primary Message:&lt;/b&gt; " + PriMsg_AP_2.Text; } else if (PriMsg_Devices_1.Checked) { message.Body += "&lt;b&gt;Primary Message:&lt;/b&gt; " + PriMsg_Devices_1.Text; } else if (PriMsg_SMB_1.Checked) { message.Body += "&lt;b&gt;Primary Message:&lt;/b&gt; " + PriMsg_SMB_1.Text; } else if (PriMsg_SMB_2.Checked) { message.Body += "&lt;b&gt;Primary Message:&lt;/b&gt; " + PriMsg_SMB_2.Text; } else if (PriMsg_SMB_3.Checked) { message.Body += "&lt;b&gt;Primary Message:&lt;/b&gt; " + PriMsg_SMB_3.Text; } else if (PriMsg_Vertical_1.Checked) { message.Body += "&lt;b&gt;Primary Message:&lt;/b&gt; " + PriMsg_Vertical_1.Text; } else if (PriMsg_Vertical_2.Checked) { message.Body += "&lt;b&gt;Primary Message:&lt;/b&gt; " + PriMsg_Vertical_2.Text; } </code></pre> <p>etc.</p> <p>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...</p> <p>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.</p> <p>Thoughts? Suggestions?</p> <p>I'm working in ASP.NET on this project.</p> <p>~Allen</p> <p>Edit: I'm using individual RadioButtons and tying them together with a GroupName. Not using a RadioButtonList. Sorry about the confusion.</p> <pre><code>&lt;asp:RadioButton ID="PriMsg_AP_1" GroupName="PriMsg" runat="server" text="Promo 1" CssClass="radiobutton" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload