O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.14. Adding a Group of RadioButton Controls

The RadioButton of Web Forms is similar to that of Windows Forms, except that by default the event is cached rather than immediately handled. In the following example I've used a RadioButtonList control instead, binding to its DataSource property in a manner similar to that of DropDownList:

private void Page_Load( object sender, System.EventArgs e )
{
    if ( ! IsPostBack )
    {
         string [] trainers = {
                  "Jennifer Juniper",
                  "Brian Bradley",
                  "Anita Anastasia"
          };

          RadioButtonList1.DataSource = trainers;
          RadioButtonList1.DataBind();
    }
}

SelectedIndexChanged() is also the event handler for this control. The SelectedIndex property identifies the selected radio button by its position within the item list. SelectedItem ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required