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

Populate RadCombo with webmethod and jquery

4 Answers 258 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Wired_Nerve
Top achievements
Rank 2
Wired_Nerve asked on 01 Aug 2013, 08:35 PM
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();
}

4 Answers, 1 is accepted

Sort by
0
Wired_Nerve
Top achievements
Rank 2
answered on 05 Aug 2013, 09:19 PM
I finally got this to work.

0
Lokesh
Top achievements
Rank 1
answered on 12 Dec 2013, 02:06 PM

Can you please post working code here??


Thanks in advance.

0
Cindi
Top achievements
Rank 1
answered on 24 Oct 2014, 09:35 AM
I also facing the same issue. can you help me in solving the above issue.
0
Wired_Nerve
Top achievements
Rank 2
answered on 29 Oct 2014, 08:55 PM
There are several moving parts here.. What are you needing help with?
Tags
ComboBox
Asked by
Wired_Nerve
Top achievements
Rank 2
Answers by
Wired_Nerve
Top achievements
Rank 2
Lokesh
Top achievements
Rank 1
Cindi
Top achievements
Rank 1
Share this question
or