This is a migrated thread and some comments may be shown as answers.

Problem with empty RadComboBoxContext

2 Answers 81 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jevgenij
Top achievements
Rank 1
Jevgenij asked on 12 Mar 2012, 01:11 PM
Hi all,

I'm facing the problem while using the RadComboBox. I've used the example from Telerik Demo to populate RadComboBox with data on demant in a new empty project. And when the control calls for the WCF service for data the RadComboBoxContext parameter is empty.
Can you please advice me what I'm doing wrong?

ASPX code:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>   
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
      <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
 
        <telerik:RadComboBox runat="server" ID="RadComboBox1" Height="100px"
            EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
            EmptyMessage="Type here ...">
            <WebServiceSettings Path="~/ComboBoxWcfService.svc" Method="LoadData" />
        </telerik:RadComboBox>
    </div>
    <asp:LinqDataSource ID="LinqDataSource1" runat="server">
</asp:LinqDataSource>
</asp:Content>


WCF code:
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ComboBoxWcfService {
    public void DoWork()
    {
    }
    [OperationContract]
    public RadComboBoxData LoadData(RadComboBoxContext context)
    {
        //The RadComboBoxData object contains all required information for load on demand:
        // - the items
        // - are there more items in case of paging
        // - status message to be displayed (which is optional)
 
        AdventureWorksDataContext northwind = new AdventureWorksDataContext();
 
 
         
        RadComboBoxData result = new RadComboBoxData();
 
        //Get all items from the Customers table. This query will not be executed untill the ToArray method is called.
        var allCustomers = from customer in northwind.Customers
                           orderby customer.ContactName
                           select new RadComboBoxItemData
                           {
                               Text = customer.ContactName
                           };
 
 
        //In case the user typed something - filter the result set
        string text = context.Text;
        if (!String.IsNullOrEmpty(text))
        {
            allCustomers = allCustomers.Where(item => item.Text.StartsWith(text));
        }
        //Perform the paging
        // - first skip the amount of items already populated
        // - take the next 10 items
        int numberOfItems = context.NumberOfItems;
        var customers = allCustomers.Skip(numberOfItems).Take(10);
 
        //This will execute the database query and return the data as an array of RadComboBoxItemData objects
        result.Items = customers.ToArray();
 
 
        int endOffset = numberOfItems + customers.Count();
        int totalCount = allCustomers.Count();
 
        //Check if all items are populated (this is the last page)
        if (endOffset == totalCount)
            result.EndOfItems = true;
 
        //Initialize the status message
        result.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>",
                                       endOffset, totalCount);
 
        return result;
    }
}

WebConfig:
<service behaviorConfiguration="metadataAndDebug" name="WebApplication1.ComboBoxWcfService">
  <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding"
    contract="WebApplication1.ComboBoxWcfService" />
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>



2 Answers, 1 is accepted

Sort by
0
Accepted
Ivana
Telerik team
answered on 15 Mar 2012, 03:02 PM
Hi Jevgenij,

The following help article explains how to create load on demand RadComboBox which loads its items from a WCF service: [http://www.telerik.com/help/aspnet-ajax/combobox-load-on-demand-wcf-service.html]. Take a look at it and see if it will help.

All the best,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jevgenij
Top achievements
Rank 1
answered on 15 Mar 2012, 07:46 PM
The link you provided helped me to understand where the problem was - I should have used Ajax-enabled WCF.
I had to use AjaxBehavior instead of WebBehavior:
    <behavior name="AjaxBehavior">
      <enableWebScript />
    </behavior>
    <behavior name="WebBehavior">
      <webHttp />
    </behavior>
Thank you very much for your help!





Tags
ComboBox
Asked by
Jevgenij
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Jevgenij
Top achievements
Rank 1
Share this question
or