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

Can't get databound value of dropdownlist

I use javascript in asp.core. I have follow problem:

I have a list wich includes a ID and a Name. I display Name in dropdown list as follow:

  $("#TypeList").ejDropDownList({
                dataSource: dataManagerType,
                fields: { value: "Name", text: "TypeId" },
                enableFilterSearch: true,
                enabled: true,
                change: "GetSpecList",
                validationRules: { required: true },
                validationMessage: { required: 'is required.' },
            });

What I want is to get selected value of dropdown list (Name). 
I tried follow code:

alert(TypeList.value); 

I get only the "ID" not the name. If I use TypeList.Text i get: "undefined"


1 Reply

KR Keerthana Rajendran Syncfusion Team November 7, 2019 06:49 AM UTC

Hi Marvin,  
 
 
Greetings from Syncfusion support.  
 
In DropDownList, text field will be displayed as DropDownList items and value field will be processed internally for selection. You can get the selected value from DropDownList through getSelectedValue()  method using instance of DropDownList. Please refer to the following code 
 
<script> 
    function getValue(args) 
      { 
         var ddl = $("#TypeList").data("ejDropDownList"); 
        alert(ddl.getSelectedValue()); 
         
      } 
</script> 
 
 
You can also get the selected value and text through arguments of change event during selection. Refer the following code 
 
$("#TypeList").ejDropDownList({ 
        dataSource: dataManagerType, 
        fields: { value: "Name", text: "TypeId" }, 
        enableFilterSearch: true, 
        enabled: true, 
        change: "GetSpecList", 
        validationRules: { required: true }, 
        validationMessage: { required: 'is required.' }, 
    }); 
 
    function GetSpecList(args) { 
        console.log(args.selectedText);  // get text 
        console.log(args.selectedValue); //get value 
    } 
 
We have prepared a sample with your code for reference. Please refer to the below given link 
 
 
You can use the same in your asp.net core project. Kindly refer to the below API link of DropDownList 
 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Keerthana. 


Loader.
Live Chat Icon For mobile
Up arrow icon