New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Web Service Binding
RadSearchBox can be bound to Web service. The path to the Web 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">
<WebServiceSettings Method="GetItems" Path="WebService.asmx" />
</telerik:RadSearchBox>
To use the integrated support, the Web service should have the following signature:
C#
[WebMethod]
public SearchBoxData GetItems(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;
}