Telerik 空RadComboxContext

Telerik 空RadComboxContext,telerik,radcombobox,Telerik,Radcombobox,我在使用RadComboBox时遇到了这个问题。我使用Telerik Demo中的示例在一个新的空项目中使用demant上的数据填充RadComboBox。当控件为数据调用WCF服务时,RadComboBoxContext参数为空。 你能告诉我我做错了什么吗 <telerik:RadComboBox runat="server" ID="RadComboBox1" Height="100px" EnableLoadOnDemand="true" ShowMoreR

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

    <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>
非常感谢您的帮助

    <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>
下面是我使用的代码示例: 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服务:

    <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>
    // 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;
    }
}
//注意:您可以使用“重构”菜单上的“重命名”命令来同时更改代码、svc和配置文件中的类名“ComboBoxWcfService”。
[ServiceContract(名称空间=”)]
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
公共类ComboBoxWcfService{
公共工作
{
}
[经营合同]
公共RadComboxData加载数据(RadComboxContext上下文)
{
//RadComboxData对象包含按需加载所需的所有信息:
//-项目
//-分页时是否有更多项目
//-要显示的状态消息(可选)
AdventureWorksDataContext northwind=新建AdventureWorksDataContext();
RadComboxData结果=新的RadComboxData();
//从Customers表获取所有项目。在调用ToArray方法之前,不会执行此查询。
var allCustomers=来自northwind.Customers中的客户
orderby customer.ContactName
选择新建RadComboxItemData
{
Text=customer.ContactName
};
//如果用户键入了内容,请过滤结果集
string text=context.text;
如果(!String.IsNullOrEmpty(text))
{
allCustomers=allCustomers.Where(item=>item.Text.StartsWith(Text));
}
//执行分页
//-首先跳过已填充的项目数量
//-接下来的10项
int numberOfItems=context.numberOfItems;
var customers=allCustomers.Skip(numberOfItems.Take(10);
//这将执行数据库查询,并将数据作为RadComboBoxItemData对象数组返回
result.Items=customers.ToArray();
int endOffset=numberOfItems+customers.Count();
int totalCount=allCustomers.Count();
//检查是否已填充所有项目(这是最后一页)
if(endOffset==totalCount)
result.EndOfItems=真;
//初始化状态消息
result.Message=String.Format({1}中的项目1-{0}),
内偏移、总计数);
返回结果;
}
}
网络配置:

    <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>
      <service behaviorConfiguration="metadataAndDebug" name="WebApplication1.ComboBoxWcfService">
    <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding"
      contract="WebApplication1.ComboBoxWcfService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

我找到了窍门所在。我需要使用支持Ajax的WCF服务。所以我应该使用AjaxBehavior而不是WebBehavior:

    <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>
    <behavior name="AjaxBehavior">
      <enableWebScript />
    </behavior>
    <behavior name="WebBehavior">
      <webHttp />
    </behavior>