How to use RadioButtonList control in c#

RadioButtonList web server control radiobuttonlist control enable user to select an item from list. radiobuttonlist support data bind programmatically from database. We can also populate it manually by input list item inside radiobuttonlist tag. radiobuttonlist is a single selection radio button group. radiobuttonlist have an items collection. we can determine which item is selected by test it's SelectedItem property.

we can change dropdownlist design by setting up it's various property as like BackColor, BorderColor, BorderStyle, BorderWidth, CellPadding, CellSpacing, CssClass, Font-Bold, Font-Italic, Font-Names, Font-Overline, Font-Size etc. there are more three properties RepeatColumns, RepeatDirection and RepeatLayout which help you to place list item vertically or horizontally.

RadioButtonList have standard AutoPostBack property. As like other list control radiobuttonlist have an excellent event SelectedIndexChanged. so that when someone select an item it automatically post back the page and we can determine programmatically which item is selected now. for that we need to set AutoPostBack property value to true and setup a SelectedIndexChanged event. DataSourceID, DataTextField and DataValueField property help you to data bind radiobuttonlist with database. radiobuttonlist also support theme and skin.

in this example we demonstrate a very simple example of radiobuttonlist. select an item from radiobuttonlist and submit the form by clicking button control. you will get which item is selected from radiobuttonlist.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
        Label1.Text ="You Selected Collection: " + RadioButtonList1.SelectedItem.ToString();

<html xmlns="">
    <head runat="server">
        <title>RadioButtonList example: how to use RadioButtonList control in</title>
        <form id="form1" runat="server">
                <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Crimson"></asp:Label>
                <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                <br />
                <asp:Button ID="Button1" runat="server" Text="Show Selected Software" OnClick="Button1_Click" />
                <hr />
Related examples