SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radio Button GroupName and SelectedValue

    I have two radio buttons that are part of a groupName. I am not sure how to go about getting the SelectedValue of the group via VB in my code behind. I am not abel to use a RadioButtonList as I have HTML code between the groped radio buttons.

    Here is my code.

    Code:
    <table>
            <tr>
              <td><b>Do you... </b></td>
            </tr>
            <tr>
              <td>
                  <asp:RadioButton ID="RadioButtonHousing" runat="server" 
                      Text="Contract for Group Housing?" GroupName="RadioButtonHousingQuestions" ValidationGroup="sample" />
              </td>
            </tr>
            <tr>
              <td><b>OR</b></td>
            </tr>
            <tr>
              <td><b>Do your...</b> </td>
            </tr>
            <tr>
              <td>
               <asp:RadioButton ID="RadioButtonHousing2" runat="server" 
                      Text="Attendees independently make their own housing arrangements?" 
                      GroupName="RadioButtonHousingQuestions" ValidationGroup="sample" /> 
      </td>
            </tr>
           <tr>
              <td>
                  <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="sample"/>
                </td>
            </tr>
    </table>
    How do I get the selected value from the RadioButton GroupName=RadioButtonHousingQuestions above using VB code behind?

    I have looked all over and most are saying use a RadioButtonList, but I can't in this case.

    Thanks for any help.

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hmm. Maybe checking for the checked state of the buttons
    Code VBNET:
    If RadioButtonHousing.Checked
    Then
    [I]...[/I]
    EndIf

  3. #3
    SitePoint Wizard webcosmo's Avatar
    Join Date
    Oct 2007
    Location
    Boston, MA
    Posts
    1,480
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    if you put a groupname on regular radiobutton if you have to check which one is selected and get selected value for that.

    I would rather use a RadioButtonList.

    <asp:RadioButtonList ID="rdl" runat="server">
    <asp:ListItem Value="1">A</asp:ListItem>
    <asp:ListItem Value="2">B</asp:ListItem>
    </asp:RadioButtonList>

    then i can get the selected value as
    if(rdl.SelectedIndex!=-1)
    somevar=rdl.SelectedValue;

  4. #4
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,876
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    As stated above, you must check each button separately

    if (RadioButtonHousing.Checked) else RadioButtonHousing2 is checked


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •