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

RadComboBox with WebAPI service as DataSource

3 Answers 271 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
jsearl
Top achievements
Rank 1
jsearl asked on 09 Oct 2013, 03:13 PM
I've been looking through examples and forums and have not seen a clear example of how to bind a RadComboBox using a WebAPI service as the DataSource.  It seems that this would be supported, but I'm not having any luck getting it to work.  Thanks for any help you can provide!

3 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 14 Oct 2013, 12:20 PM
Hi,

Please find the attached sample. It demonstrates the simplest web api binding: 

<script type="text/javascript">
    $(document).ready(function () {
        var combo = $find('RadComboBox1');
        combo.requestItems();
    });
 
    function OnClientItemsRequesting(sender, args) {
        $.getJSON("api/items", function (data) {
            var items = [];
            $.each(data, function (key, val) {
                console.log(key);
                console.log(val);
                var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                comboItem.set_text(val);
                sender.get_items().add(comboItem);
            });
        });
    }
</script>
<telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientItemsRequesting="OnClientItemsRequesting"></telerik:RadComboBox>

WebAPI controller:
public class ItemsController : ApiController
{
    List<string> items = new List<string>();
 
    // GET api/<controller>
    public IEnumerable<string> Get()
    {
        for (int i = 0; i < 20; i++)
        {
            items.Add("Item " + i);
        }
        return items;
    }
}

Here is another useful forum post. Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
mark baer
Top achievements
Rank 1
answered on 12 Jun 2014, 09:33 PM
How about populating a RadGrid?  Also, I know this is not Telerik specific, but what might be a decent practice for submitting a "Web Form" to a Web API Service?  Should it be done in code behind?  Straight from the web page/jquery?

Thanks
0
Shinu
Top achievements
Rank 2
answered on 16 Jun 2014, 10:52 AM
Hi mark baer,

Please take a look into the following blogs which discuss about the same scenario.

Take a Walk on the Client Side with WebAPI and WebForms
Take a Walk on the Client Side with WebAPI and WebForms – Part 2

Thanks,
Shinu.
Tags
ComboBox
Asked by
jsearl
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
mark baer
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or