0

我在使用 RadComboBox 时遇到了这个问题。我使用 Telerik Demo 中的示例在一个新的空项目中使用 deman 上的数据填充 RadComboBox。当控件为数据调用 WCF 服务时,RadComboBoxContext 参数为空。你能告诉我我做错了什么吗?

非常感谢帮助!

这是我使用的代码示例:ASPX:

    <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>

WCF 服务:

    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ComboBoxWcfService" in code, svc and config file together.

[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;
    }
}

网络配置:

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

1 回答 1

0

我发现了诀窍在哪里。我需要使用启用 Ajax 的 WCF 服务。所以我应该使用 AjaxBehavior 而不是 WebBehavior:

    <behavior name="AjaxBehavior">
      <enableWebScript />
    </behavior>
    <behavior name="WebBehavior">
      <webHttp />
    </behavior>
于 2012-03-15T18:43:58.187 回答