We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SelectItemByValue does not work when using the WebApiAdaptor

Hi,
I am developing a MVC5 web application and  populating a dropdownlist control  using the WebApiAdaptor to make a REST call. 
When I try and select an item it does not select it.

Below is the code I am using to populate and select a value in the dropdown control.

<script>
//Page loaded
    $(function ()
    {
        $("#drpStatus").ejDropDownList({
            dataSource: ej.DataManager({
                url: "GetStatusType",                
                adaptor: new ej.WebApiAdaptor()
            }),              
            fields: { text: "Name", value: "Code" }            
        }).data("ejDropDownList").selectItemByValue("HOLD");
 });
</script>

Are you able to tell me where I am going wrong?

Thanks
        

1 Reply

KR Keerthana Rajendran Syncfusion Team August 25, 2016 12:00 PM UTC

Hi Mahindra  
  
We had checked your code. We found that you have tried to select an item by value before data has been bound to dropdownlist. We suggest you to use this selectItemByValue in actionComplete event which will be triggered after data is bound to dropdownlist.   
  
  
   
<code>   
$(function() {   
        $("#drpStatus").ejDropDownList({   
            dataSource: ej.DataManager({   
                url: "/api/Orders",   
                adaptor: new ej.WebApiAdaptor()   
            }),   
            fields: {   
                text: "CustomerID",   
                value: "CustomerID"   
            },   
            actionCompletefunction(args)   
            {   
                var ddlobj = $("#drpStatus").data("ejDropDownList")   
                ddlobj.selectItemByValue("VICTE");   
            }   
                   
      })   
       
    });</code>   
  
We have prepared a sample please find in the below link.  
                                
Please let us know if any concern   


Regards,   
Keerthana  
 


Loader.
Live Chat Icon For mobile
Up arrow icon