Edit this page

Binding to DataTable, DataSet, or DataView

RadComboBox can be bound to a DataTable, DataSet, and DataView. The following example shows binding to a DataTable object.

The declaration of RadComboBox object includes no DataSourceID property or <items> section:

<telerik:radcombobox id="RadComboBox1" runat="server" />

In the Page_Load event handler, create and fill the DataTable object, then bind it to the RadComboBox. The DataBind method must be called after setting the DataSource property.


protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        BindToDataTable(RadComboBox1);
    }

}

private void BindToDataTable(RadComboBox combo)
{

    SqlConnection con = new SqlConnection("Data Source=LOCAL;Initial Catalog=Combo;Integrated Security=True");

    SqlDataAdapter adapter = new SqlDataAdapter("SELECT [Text], [Value] FROM [Links]", con);
    DataTable links = new DataTable();

    adapter.Fill(links);

    combo.DataTextField = "Text";
    combo.DataValueField = "Value";
    combo.DataSource = links;
    combo.DataBind();
}


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        BindToDataTable(RadComboBox1)
    End If
End Sub 'Page_Load

Private Sub BindToDataTable(ByVal combo As RadComboBox)

    Dim con As New SqlConnection("Data Source=LOCAL;Initial Catalog=Combo;Integrated Security=True")

    Dim adapter As New SqlDataAdapter("SELECT [Text], [Value] FROM [Links]", con)
    Dim links As New DataTable()

    adapter.Fill(links)

    combo.DataTextField = "Text"
    combo.DataValueField = "Value"
    combo.DataSource = links
    combo.DataBind()
End Sub 'BindToDataTable