New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Server-side Data Binding Overview

The article shows how to set up RadCheckBoxList with data binding.

RadCheckBoxList can use the standard data sources for binding an ASP.NET control:

  • Declarative ASP.NET data sources (SqlDatasource, ObjectDataSource, LinqDataSource, etc.)
  • Server-side collections that implement the IEnumerable interface.

Server-side Data Binding Basics

RadCheckBoxList exposes the Databindings composite property to configure the fields needed for data binding:

  • DataTextField binds the Text property of the items with the corresponding field.
  • DataValueField binds the Value property of the items with the corresponding field.
  • DataSelectedField binds the Selected property of the items with the corresponding field.
  • DataEnabledField binds the Enabled property of the items with the corresponding field.

Example 1: Data binding RadCheckBoxList with a collection in the code behind.

ASP.NET
<telerik:RadCheckBoxList runat="server" ID="RadCheckBoxList1">
    <Databindings DataTextField="Text" DataValueField="Value" 
        DataSelectedField="Selected" DataEnabledField="Enabled" />
</telerik:RadCheckBoxList>
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        RadCheckBoxList1.DataSource = GetData();
        RadCheckBoxList1.DataBind();
    }
}

private IEnumerable<object> GetData()
{
    List<object> result = new List<object>() {
        new { Text = "English", Value = "en",
                Selected = true, Enabled = true },
        new { Text = "German", Value = "de",
                Selected = false, Enabled = true },
        new { Text = "french", Value = "fr",
                Selected = false, Enabled = true }
    };

    return result;
}

See Also