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
close icon

data("ejDropDownList") is undefined.


I've created a simple dropdown list as such:

@Html.EJ().DropDownList("ddlLoginName").WatermarkText("Select Login Name").DropDownListFields(Sub(f) f.Text("LoginName").Value("Id")).Width("15em").Datasource(CType(ViewBag.listOfLogin,IEnumerable(Of Login)))

And tried to use the javascript to get its selected value:

$("#ddlLoginName").data("ejDropDownList")

The result is always empty/undefined.

It seems like data("ejDropDownList") works only in certain scenario but it wasn't documented.

1 Reply

SS Saranya Sivakumar Syncfusion Team November 3, 2014 10:38 AM UTC

Hi CS,

Thanks for using Syncfusion products.

We would like to let you know that, in Dropdownlist control we are having a method called “getSelectedValue” which is used to get the selected item value in the Dropdownlist. It returns null or undefined if we didn’t specify the value field in the Datasource. If we specify the value field then it will return the value of the selected item. We are having another method called “getValue” which is used to get the text of the selected item in the Dropdownlist. So include the following code snippet in the click event of the Button.

[Script]

function click()

    {

        var obj = $('#selectCar').data('ejDropDownList');

        var a = obj.getValue();

        alert(a);

    }

 

For your convenience we have prepared the sample based on your requirement, please find the sample from the following location.

Sample Location: Sample

You can also refer the following class reference link for JavaScript. Since, our ASP.NET MVC components are created as wrapper for the JavaScript components the properties, methods and events will be same for MVC components.

http://help.syncfusion.com/cr/js

Please let us know if you have further concern.

Regards,

Saranya.S


Loader.
Live Chat Icon For mobile
Up arrow icon