Hi everyone,


I have a bunch of radio button with same group/name so only one selected from them which is required, i want selected value on my .cs page but i am unable to do this, please help me.

<table> 
<tr>
                      <td class="FourtyOfTr">Self Plan Only</td>
                      <td class="TwelveOfTr">
                      <input ID="Radio1" type="radio" value="675" name="Premium" runat="server"/> 0675</td>
                      <td class="TwelveOfTr">
                      <input ID="Radio2" type="radio" value="1069" name="Premium" runat="server"/> 1069
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio3" type="radio" value="1464" name="Premium" runat="server"/> 1464
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio4" type="radio" value="2137" name="Premium" runat="server"/> 2137
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio5" type="radio" value="2926" name="Premium" runat="server"/> 2926
                      </td>
                      </tr>
                        <tr>
                      <td class="FourtyOfTr">Self & Family Plan</td>
                     <td class="TwelveOfTr">
                          
                          <input ID="Radio6" type="radio" value="1609" name="Premium" runat="server"/> 1609</td>
                      <td class="TwelveOfTr">
                      <input ID="Radio7" type="radio" value="2456" name="Premium" runat="server"/> 2456
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio8" type="radio" value="3307" name="Premium" runat="server"/> 3307
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio9" type="radio" value="4906" name="Premium" runat="server"/> 4906
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio10" type="radio" value="6607" name="Premium" runat="server"/> 6607
                      </td>
                      </tr>
                        <tr>
                      <td class="FourtyOfTr">Self Plan + Dependent Parents Add - on</td>
                     <td class="TwelveOfTr">
                          
                          <input ID="Radio11" type="radio" value="1640" name="Premium" runat="server"/> 1640</td>
                      <td class="TwelveOfTr">
                      <input ID="Radio12" type="radio" value="2034" name="Premium" runat="server"/> 2034
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio13" type="radio" value="2429" name="Premium" runat="server"/> 2429
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio14" type="radio" value="3102" name="Premium" runat="server"/> 3102
                      </td>
                      <td class="TwelveOfTr">
                      <input ID="Radio15" type="radio" value="3891" name="Premium" runat="server"/> 3891
                      </td>
                      </tr>
                 
                      </tr>
                       
                      </table>

i want selected value on my code file, how can i do it because on cade page its shows individual control so i need to check all control, there is any other option where i can get value in one step.


Thanks in advance

Recommended Answers

All 5 Replies

you have to do something like this.

foreach (Control cn in form1.Controls)
            {
                if (cn.GetType().Name == "RadioButton")
                {
                    RadioButton rd = (RadioButton)cn;
                    if (rd.GroupName == "a" && rd.Checked)
                    {
                        TextBox1.Text = rd.Text;
                    }
                }
            }

After postback i think request object can resolve your problem.

As all radio buttons have the same name 'Premium', Request.Params["Premium"].ToString() will return the value of the radio button selected.

For example,

TextBox1.Text = Request.Params["Premium"].ToString();

Use GroupName property of radio button. It creates a group of radio buttons.

Another control - RadioButtonList can be used for same purpose.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.