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

Setting the selected property in a dropdown control when editing a record using a Dialog form.

Hi,

I am trying to set the selected property on a dropdown control when editing an existing record in a grid control. 

When the Dialog form is shown, I make an ajax call to the controller to populate the dropdown control using these grid events  if (args.requestType == "beginedit" || args.requestType == "add")
After the control is loaded, I execute the following code.

  $("#CountryCode").find("option:contains('GBR')").each(function ()
                    {
                        if ($(this).text() == 'GBR')
                        {
                            $(this).attr("selected", "selected");
                        }
                    });

The dropdown control does not show any text in the dropdown area. However when clicking on the control I can select from the values added from the ajax call.

Is there something obvious I am doing something wrong.

Thanks fro your help.



1 Reply

VA Venkatesh Ayothi Raman Syncfusion Team March 10, 2016 01:52 PM UTC

Hi Mahindra,

Thanks for using Syncfusion product.

We have achieved your requirement ”Bind a new datasource to dropdownlist while editing or adding” using actionComplete event. If we add or edit a record then it bind a new datasource for dropdown list through AJAX call to the controller. We gave a default selected value for dropdown using selectItemByValue method in dropdown control. We have created a sample and refer to the code example,
Code Example:

<View page and Ajax call>

<script type="text/javascript">


    function actionComplete(e) {


      

        if (e.requestType == "beginedit" || e.requestType == "add") { //AJAX method call

            $.ajax({


                url: "/Grid/Getlist",

                method: "POST",

                success: function (list) {

                   

                    var obj = $("#FlatGridShipName").data("ejDropDownList");

                    $("#FlatGridShipName").ejDropDownList({ dataSource: list });

                    obj.selectItemByValue("Argus"); //Set a value for Dropdown List while editing or Adding


                }


            });

        }


    }   

</script>



Sample:Dropdowneditingindialog


Regards,
Venkatesh Ayothiraman.

Loader.
Up arrow icon