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

Populating Combobox with Web service

1 Answer 103 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Harminder
Top achievements
Rank 1
Harminder asked on 29 Jun 2012, 01:29 PM
Hi Team,

I've been struggling with this for couple of hours, the Combobox does not seem to fill up with the web service.
This is the web service i'm using

namespace WebApplication
{
    /// <summary>
    /// Summary description for vendorsearch
    /// </summary>
    [WebService(Namespace = "http://jnkdfjdf.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class comboboxsearch : System.Web.Services.WebService
    {
        [WebMethod]
        public IEnumerable GetItems(RadComboBoxContext context)
        {
            RadComboBoxData result = new RadComboBoxData();
            int numberOfItems = (int)(context["ItemsCount"] ?? 1000);
 
            List<ComboBoxItemData> items = new List<ComboBoxItemData>();
            for (int i = 0; i < numberOfItems; i++)
            {
                ComboBoxItemData itemData = new ComboBoxItemData();
                itemData.Text = "Item " + i;
                items.Add(itemData);
            }
 
            return items;
        }
    }


And here is the asp.net default.aspx code

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication._Default" %>
 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
     
 
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="Panel1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="Panel1" />
                    <telerik:AjaxUpdatedControl ControlID="RadComboBox1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
 
   <telerik:RadComboBox ID="RadComboBox1" CssClass="ComboBox" runat="server" Width="240px" Height="200px"
        OnClientItemsRequested="OnClientItemsRequested" OnClientItemsRequesting="OnClientItemsRequesting"
        EnableLoadOnDemand="true" OnClientDropDownClosed="OnClientDropDownClosed" EnableItemCaching="true">
        <ExpandAnimation Type="none" />
        <CollapseAnimation Type="none" />
        <WebServiceSettings Path="comboboxsearch.asmx" Method="GetItems" />
    </telerik:RadComboBox>
 
 
    <telerik:RadScriptBlock runat="Server" ID="RadScriptBlock1">
 
    </telerik:RadScriptBlock>
  
 
</asp:Content>

What could i be possibly doing wrong? , any help will be appreciated :) .


Cheers

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Jul 2012, 06:11 AM
Hi Harminder,

Here is the sample code which I tried based on your scenario which works as expected. Please make sure that you are not getting any Javascript errors.

JS:
<script type="text/javascript">
   function OnClientItemsRequesting(sender, args)
   {
      args.get_context()["ItemsCount"] = 100;
      startTime = new Date();
   }
  
   function OnClientItemsRequested(sender, args)
   {
   }
   function OnClientDropDownClosed(sender, args)
   {
      sender.clearItems();
      if (args.get_domEvent().stopPropagation)
          args.get_domEvent().stopPropagation();
   }
</script>

comboboxsearch.cs :
public class comboboxsearch : System.Web.Services.WebService
{
 
    [WebMethod]
    public IEnumerable GetItems(RadComboBoxContext context)
    {
        RadComboBoxData result = new RadComboBoxData();
        int numberOfItems = (int)(context["ItemsCount"] ?? 1000);
 
        List<ComboBoxItemData> items = new List<ComboBoxItemData>();
        for (int i = 0; i < numberOfItems; i++)
        {
            ComboBoxItemData itemData = new ComboBoxItemData();
            itemData.Text = "Item " + i;
            items.Add(itemData);
        }
 
        return items;
    }
    public class ComboBoxItemData
    {
        private string text;
 
        public string Text
        {
            get { return text; }
            set { text = value; }
        }
    }
}

Thanks,
Princy.
Tags
ComboBox
Asked by
Harminder
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or