How to check that RadioButtonList has a selected item in

RadioButtonList check if selected
RadioButtonList web server control render a single selection radio button group in web browser. so users can select only one item from the radiobuttonlist control at a time. the following c# example code demonstrate us how can we check (determine) that a radiobuttonlist have any item selected or not.

radiobuttonlist SelectedIndex property get or set the lowest ordinal index of the selected items in the list. the default value of SelectedIndex property is -1 which indicates that no item is selected. radiobuttonlist items indexes are start from zero (0).

so we can test the selected index value to determine that any item in radiobuttonlist is selected or not. if the SelectedIndex property value is lower than zero (0) or equal to -1 then the radiobuttonlist is not selected. and if the SelectedIndex property value equal to zero or greater than zero then one item is selected in radiobuttonlist.

<%@ Page Language="C#" AutoEventWireup="true"%>    
<!DOCTYPE html>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
            RadioButtonList1.Items.Add(new ListItem("English Oak", "1"));
            RadioButtonList1.Items.Add(new ListItem("Pin Oak", "2"));
            RadioButtonList1.Items.Add(new ListItem("Scarlet Oak", "3"));
            RadioButtonList1.Items.Add(new ListItem("Spanish Oak", "4"));
            RadioButtonList1.Items.Add(new ListItem("Swamp White Oak", "5"));

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