- Data bind a RadioButtonList on page load

Data bind RadioButtonList on page load
The following c# example code demonstrate us how can we populate a RadioButtonList control on Page Load event. RadioButtonList is an list web server control. RadioButtonList control render a group of radio button controls where each ListItem object represent a radio button.

We can populate RadioButtonList with items by data binding with many data source objects such as SqlDataSource, ObjectDataSource, AccessDataSource, XmlDataSource, Array, ArrayList etc. To data bind a RadioButtonList with a data source object, first we need to initialize the data source object with elements. Next, we need to specify the data source object as RadioButtonList control's data source by using its DataSource property. Then we can call the RadioButtonList DataBind() method to populate it with items.

In this tutorial, we populated a RadioButtonList from an Array object. Array is very popular data source to data bind with a list web server control. We perform the data binding in Page Load event. So data binding occurs before the control display in web browser.

We also can perform data binding only one time when the page first time load in web browser. Page.IsPostBack property allow us to determine whether the page is rendered in first time or the page is in postback mode.

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

<!DOCTYPE html>

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
        string[] colorList = { "DeepPink", "DeepSkyBlue", "MediumBlue", "Pink", "Plum" };
        RadioButtonList1.DataSource = colorList;

<html xmlns="">
<head id="Head1" runat="server">
    <title>How to data bind RadioButtonList on page load</title>
    <form id="form1" runat="server">
        <h2 style="color:Maroon">RadioButtonList: DataBind</h2>
             Text="Color List"
More examples