Edit this page

Binding to DataTable

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

Binding to a DataTable at runtime

The declaration of RadSearchBox in the markup does not include DataSourceID property.

<telerik:RadSearchBox RenderMode="Lightweight" runat="server" ID="RadSearchBox1" >
    <DropDownSettings Height="400" Width="300" />
</telerik:RadSearchBox>

In the Page_Load event handler, create and fill the DataTable object, then setting the DataSource property.


protected void Page_Load(object sender, EventArgs e)
{
    RadSearchBox1.DataSource = GetData();
    RadSearchBox1.DataTextField = "ProductName";
    RadSearchBox1.DataValueField = "ProductID";
}

private static DataTable GetData()
{
    SqlDataAdapter adapter = new SqlDataAdapter(@"SELECT [ProductID], [ProductName], [SupplierID], [CategoryID], [QuantityPerUnit], [UnitPrice], 
    [UnitsInStock], [UnitsOnOrder], [ReorderLevel], [Discontinued] FROM [Products]",
        ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);

    DataTable data = new DataTable();
    adapter.Fill(data);

    return data;
}


Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    RadSearchBox1.DataSource = GetData()
    RadSearchBox1.DataTextField = "ProductName"
    RadSearchBox1.DataValueField = "ProductID"
End Sub

Private Shared Function GetData() As DataTable
    Dim adapter As New SqlDataAdapter("SELECT * FROM [Products]", ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)

    Dim data As New DataTable()
    adapter.Fill(data)

    Return data
End Function

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

Give article feedback

Tell us how we can improve this article

close
Dummy