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

WCF Service Binding

RadSearchBox supports WCF binding. The following steps demonstrate how to bind RadSearchBox through WCF service.

The path to the service and the name of the service method are specified in the WebServiceSettings' Path and Method properties:

ASPNET
<telerik:RadSearchBox RenderMode="Lightweight" runat="server" ID="RadSearchBox1">
	<DropDownSettings Height="400" Width="300" />
	<WebServiceSettings Path="LoadEntriesWCF.svc" Method="GetResults" />
</telerik:RadSearchBox>

To use the integrated support, the Web service should have the following signature:

C#
	
[OperationContract]
public static SearchBoxData GetResults(SearchBoxContext context)
{
	DataTable data = GetData(context.Text);

	List<SearchBoxItemData> items = new List<SearchBoxItemData>();

	for (int i = 0; i < data.Rows.Count; i++)
	{
		SearchBoxItemData itemData = new SearchBoxItemData();
		itemData.Text = data.Rows[i]["ProductName"].ToString();
		itemData.Value = data.Rows[i]["ProductId"].ToString();

		items.Add(itemData);
	}

	SearchBoxData result = new SearchBoxData();
	result.Items = items.ToArray();
	return result;
}

private static DataTable GetData(string filterString)
{
	SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
	SqlCommand command = new SqlCommand("SELECT [ProductId], [ProductName] FROM [Products] WHERE [ProductName] LIKE '%' + @filterString + '%' ORDER BY [ProductId]");
	command.Parameters.AddWithValue("@filterString", filterString);
	command.Connection = connection;
	SqlDataAdapter adapter = new SqlDataAdapter(command);

	DataTable data = new DataTable();
	adapter.Fill(data);
	return data;
}
	
Not finding the help you need?
Contact Support