Populate RadCombo with webmethod and jquery

5 posts, 0 answers
  1. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 01 Aug 2013 Link to this post

    I have been digging around a bit looking for a good example of how to take a radcombobox and populate it using a webmethod and jquery combined... I think I am just missing something rather simple.. Any suggestions?

    This is NOT a mvc project, but a traditional asp.net web forms


    // This cancels the default RadComboBox behavior
    function itemsRequesting(sender, args) {
        if (args.set_cancel != null) {
            args.set_cancel(true);
        }
        if (sender.get_emptyMessage() == sender.get_text())
            sender.set_text("");
    }
     
    function getSites(sender, args) {
        var url = baseUrl + "TagManagement/Tags.aspx/GetSiteList";
         
        $.ajax({
            async: false,
            type: "POST",
            url: url,
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d == null) {
                    alert("The filter set returned no records");
                    } else {
     
                    fillCombo(sender, msg);
     
                }
            }
        }).complete(function () {
            $.unblockUI();
     
        });
     
    return false;
     
    }
     
    function fillCombo(combo, result) {
        combo.clearItems();
     
        var items = result.d || result;
         
        // This just lets user know that nothing was returned with their search
        if (items.length == 0) {
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            comboItem.set_text("Nothing found");
            comboItem.set_value("null");
            combo.get_items().add(comboItem);
            combo.set_text("");
        }
     
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
     
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            comboItem.set_text(item.Text);
            comboItem.set_value(item.Value);
            combo.get_items().add(comboItem);
        }
    }

    The Control :
    <telerik:RadComboBox ID="RadComboBoxTransferSites" runat="server" CheckBoxes="true" EnableLoadOnDemand="true" OnClientItemsRequesting="getSites"
                                      EnableCheckAllItemsCheckBox="true" DataTextField="SiteName" DataValueField="SiteUID"
                                      EmptyMessage="Please Select...">
                                  </telerik:RadComboBox>

    The web method:
    [WebMethod]
    public static List<SiteList> GetSiteList()
    {
        var siteList = (List<SiteList>)HttpContext.Current.Session["SiteList"];
        return siteList.ToList();
    }
  2. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 05 Aug 2013 Link to this post

    I finally got this to work.

  3. Lokesh
    Lokesh avatar
    7 posts
    Member since:
    Jan 2012

    Posted 12 Dec 2013 Link to this post

    Can you please post working code here??


    Thanks in advance.

  4. KG
    KG avatar
    2 posts
    Member since:
    Oct 2014

    Posted 24 Oct 2014 Link to this post

    I also facing the same issue. can you help me in solving the above issue.
  5. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 29 Oct 2014 in reply to KG Link to this post

    There are several moving parts here.. What are you needing help with?
Back to Top