c# RadioButtonList control example

RadioButtonList control example
RadioButtonList is an list web server control. RadioButtonList control render a group of radio button controls where each radio button share a same group name. RadioButtonList control encapsulate a radio group. RadioButtonList control's each ListItem object render a single radio button control.

RadioButtonList control's items exists in an items collection. So we can manage (edit, insert and delete) RadioButtonList items collection by .net framework's Collection<T> Class methods and properties. RadioButtonList control has many built in properties to design and style the control itself such as BackColor, ForeColor, CssClass etc. We also can customize its items level style by core CSS style such each different colors for different items.

RadioButtonList control's AutoPostBack property and SelectedIndexChanged event allow us to quickly get the users item selection after each time RadioButtonList selection has changed.

In this following example code, we populated a RadioButtonList control with items by declarative syntax in tag section. We also keep the AutoPostBack property value to 'True' and write an event handler for its SelectedIndexChanged event. So when users change the RadioButtonList item selection we caught the selection on SelectedIndexChanged event handler section and display an image on web page which is specified by RadioButtonList present selected item.

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

<!DOCTYPE html>

<script runat="server">
    protected void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e) {
        Image1.ImageUrl = "Images/" + RadioButtonList1.SelectedItem.Text.ToString();

<html xmlns="">
<head runat="server">
    <title>RadioButtonList simple example</title>
    <form id="form1" runat="server">
        <asp:Image ID="Image1" runat="server" />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Select for view image"></asp:Label>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="true">
More examples