New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Loading items from WebService
Fetching server data using ASP.NET Web Services to ensure responsive, dynamic applications with minimal overhead, enhancing both performance and user experience.
Web services are components on a Web server that a client application can call by making HTTP requests across the Web.
If you need help setting up the WebService, you can check out the Quick Walkthrough ASP.NET WebService article.
ComboBox settings for loading the items from Web Service:
- Set the
EnableLoadOnDemand
property totrue
. - Provide the path to the Web Service and the name of the method for the
Path
andMethod
properties of theWebServiceSettings
element.
Web Service specifics:
- Method return
Type
should be a collection ofRadComboBoxItemData
objects. To use custom objects, check out the Custom ComboBox Item Data section.
XML Web Service (ASMX)
ComboBox Markup
ASP.NET
<telerik:RadComboBox ID="RadComboBox1" runat="server" RenderMode="Lightweight" EnableLoadOnDemand="true">
<WebServiceSettings Path="WebService.asmx" Method="GetProducts"></WebServiceSettings>
</telerik:RadComboBox>
Web Service method
C#
[WebMethod]
public List<RadComboBoxItemData> GetProducts(RadComboBoxContext context)
{
string userText = context.Text;
List<RadComboBoxItemData> allItems = Enumerable.Range(0, 100).Select(x => new RadComboBoxItemData()
{
Text = "Product " + x,
Value = x.ToString()
}).ToList();
List<RadComboBoxItemData> filteredItems = allItems.Where(item => item.Text.Contains(userText)).ToList();
return filteredItems;
}
WCF Service (SVC)
ComboBox Markup
ASP.NET
<telerik:RadComboBox ID="RadComboBox1" runat="server" RenderMode="Lightweight" EnableLoadOnDemand="true">
<WebServiceSettings Path="Service.svc" Method="GetProducts"></WebServiceSettings>
</telerik:RadComboBox>
Web Service method
C#
[OperationContract]
public List<RadComboBoxItemData> GetProducts(RadComboBoxContext context)
{
string userText = context.Text;
List<RadComboBoxItemData> allItems = Enumerable.Range(0, 100).Select(x => new RadComboBoxItemData()
{
Text = "Product " + x,
Value = x.ToString()
}).ToList();
List<RadComboBoxItemData> filteredItems = allItems.Where(item => item.Text.Contains(userText)).ToList();
return filteredItems;
}
PageMethod
ComboBox Markup
ASP.NET
<telerik:RadComboBox ID="RadComboBox1" runat="server" RenderMode="Lightweight" EnableLoadOnDemand="true">
<WebServiceSettings Path="Default.aspx" Method="GetProducts"></WebServiceSettings>
</telerik:RadComboBox>
CodeBehind method
C#
[WebMethod]
public static List<RadComboBoxItemData> GetProducts(RadComboBoxContext context)
{
string userText = context.Text;
List<RadComboBoxItemData> allItems = Enumerable.Range(0, 100).Select(x => new RadComboBoxItemData()
{
Text = "Product " + x,
Value = x.ToString()
}).ToList();
List<RadComboBoxItemData> filteredItems = allItems.Where(item => item.Text.Contains(userText)).ToList();
return filteredItems;
}
Check out the Online Examples at Load on Demand Modes.
Custom ComboBox Item Data
In case of custom models inherit the Telerik.Web.UI.ControlItemData
Class.
C#
public class CustomComboItemData : ControlItemData
{
// Inherited Members
// Custom Members
public string CustomField1 { get; set; }
public string CustomField2 { get; set; }
}
Example Usage
C#
public List<CustomComboItemData> GetProducts(RadComboBoxContext context)
{
string userText = context.Text;
List<CustomComboItemData> allItems = Enumerable.Range(0, 100).Select(x => new CustomComboItemData()
{
Text = "Product " + x,
Value = x.ToString()
}).ToList();
List<CustomComboItemData> filteredItems = allItems.Where(item => item.Text.Contains(userText)).ToList();
return filteredItems;
}