Welcome Guest.   Make a donation to an author on the site July 31, 2014, 08:32:50 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2014! Download dozens of custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: <asp:RadioButton /> Determining which is selected without javascript  (Read 2537 times)
h0meopathic
Participant
*
Posts: 24

View Profile Give some DonationCredits to this forum member
« on: July 30, 2009, 02:55:22 PM »

I have 36 radio buttons in a form, all with the same groupName, and all with different IDs.  Is it possible to find out which ID is selected without fishing for it? Surely a dynamic control such as a radiobutton wouldn't have been made without a simple way of finding out which button was selected.
Logged
housetier
Charter Honorary Member
***
Posts: 1,321


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #1 on: July 30, 2009, 04:21:35 PM »

go check out asp:RadioButtonList, it has a bunch of properties that start with "Selected"
Logged
h0meopathic
Participant
*
Posts: 24

View Profile Give some DonationCredits to this forum member
« Reply #2 on: July 30, 2009, 06:17:09 PM »

You have to make a radiobuttonlist as follows

Formatted for HTML with the GeSHI Syntax Highlighter [copy or print]
  1. <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
  2.                    RepeatColumns="3" TextAlign="Left">
  3.                    <asp:ListItem Value="1">07:00AM-07:15AM</asp:ListItem>
  4.                    <asp:ListItem Value="2">07:15AM-07:30AM</asp:ListItem>
  5.                    <asp:ListItem Value="3">07:30AM-07:45AM</asp:ListItem>
  6.                    <asp:ListItem Value="4">07:45AM-08:00AM</asp:ListItem>
  7.                </asp:RadioButtonList>

Then add some statements to make sure its working (inside submitButton_Click). radioButton is my label
Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. if (RadioButtonList1.SelectedIndex > -1)
  2.        {
  3.            radioButton.Text = "<br />you selected: " + RadioButtonList1.SelectedIndex.ToString();
  4.        }
  5.        else
  6.        {
  7.            radioButton.Text = "Select a radio button";
  8.        }

Then attache it to the database like so:
Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. appNameComm = new SqlCommand("INSERT INTO AppointmentName (LastName, FirstName, Email, BirthDate, Slot) " +
  2.                "VALUES (@LastName, @FirstName, @Email, @BirthDate, @Slot)", conn);
  3. .
  4. .
  5. .
  6. appNameComm.Parameters.Add("@Slot", System.Data.SqlDbType.Int, 2);
  7.            appNameComm.Parameters["@Slot"].Value = RadioButtonList1.SelectedIndex.ToString();
Logged
housetier
Charter Honorary Member
***
Posts: 1,321


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #3 on: July 30, 2009, 06:42:35 PM »

be sure to check that SelectedWhatever is not null. Never trust user input and even a selected radio button is user input.
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.05s | Server load: 0.11 ]