New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
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.
ASPNET
<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.
C#
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;
}