How to set a default selected item in RadioButtonList in

RadioButtonList Default Selected Item radiobuttonlist web server control display a single selection radio button group in web browser. by default radiobuttonlist control have no selected item when initialize it in web browser. the following c# example code demonstrate us how can we create a radiobuttonlist with default selection.

RadioButtonList server control contains ListItem objects. ListItem can have Text, Value and Selected property. Selected property get or set a Boolean value indicating whether the item is selected. so if we can assign radiobuttonlist any item's Selected property value to True, then the radiobuttonlist control will display in web browser with default selection. when user submit the form without selecting any item from radiobuttonlist control then the radiobuttonlist default selection is post to the web server. users also can change the default selection of radiobuttonlist server control.

RadioButtonList default selection automatically works as requiredfieldvalidator control, because users must select an item from radiobuttonlist before submit the web form.

In this example code we check that radiobuttonlist control have any selected item or not in Page Load event. if user submit the from without selecting any item from radiobuttonlist control then we programmatically set the radiobuttonlist selected index as a default selected item.

<%@ Page Language="C#" AutoEventWireup="true"%>    
<!DOCTYPE html>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
            RadioButtonList1.Items.Add(new ListItem("Giant Onion", "1"));
            RadioButtonList1.Items.Add(new ListItem("Tree Onion", "2"));
            RadioButtonList1.Items.Add(new ListItem("Osage Orange", "3"));
            RadioButtonList1.Items.Add(new ListItem("Wild Orange", "4"));
            RadioButtonList1.Items.Add(new ListItem("Parsnip", "5"));

        if (RadioButtonList1.SelectedIndex < 0)
            RadioButtonList1.SelectedIndex = 0;
            Label1.Text += "radiobuttonlist shows default selected item.";
            Label1.Text = "you selected an item : " + RadioButtonList1.SelectedItem.Text;
<html xmlns="">        
<head id="Head1" runat="server">        
    <title> radiobuttonlist default selected</title>
    <form id="form1" runat="server">        
        <h2 style="color:MidnightBlue; font-style:italic;">        
   example - radiobuttonlist default selected
        <hr width="550" align="left" color="Gainsboro" />        
        <br /><br />
More examples