Edit this page

Binding to DataTable, DataSet or DataView

RadListBox can be bound to a DataTable, DataSet and a DataView. This example shows binding to a DataTable object.

The declaration of the RadListBox object includes no DataSourceID property or section:

<telerik:radlistbox id="RadListBox1" runat="server"></telerik:radlistbox>

In the Page_Load event handler, create and fill the DataTable object, then bind it to the ListBox. You must call the DataBind method after setting the DataSource property.

protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        RadListBox1.DataSource = GetData(); 
        RadListBox1.DataTextField = "ProductName"; 
        RadListBox1.DataValueField = "ProductID"; 
protected DataTable GetData()
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT ProductID, ProductName FROM Products", ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
    DataTable result = new DataTable(); adapter.Fill(result);
    return result;
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If Not IsPostBack Then
        RadListBox1.DataSource = GetData()
        RadListBox1.DataTextField = "ProductName"
        RadListBox1.DataValueField = "ProductID"
    End If
End Sub
Protected Function GetData() As DataTable
    Dim adapter As New SqlDataAdapter("SELECT ProductID, ProductName FROM Products", ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)
    Dim result As New DataTable()
    Return result

End Function

See Also

Is this article helpful? No Yes
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article