Populating Combobox with Web service

2 posts, 0 answers
  1. Harminder
    Harminder avatar
    1 posts
    Member since:
    Jun 2012

    Posted 29 Jun 2012 Link to this post

    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

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Jul 2012 Link to this post

    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.
Back to Top