DropdownList not showing Text on load

Hi,

I'm using a dropdown list as follow:

<ejs-dropdownlist id="Address1TypeCode" placeholder="@Html.DisplayNameFor(m => m.BusinessUnit.Address1TypeCode)" popupHeight="auto"
dataSource="@Html.GetEnumSelectList<AddressTypeCode>     ()" ejs-for="@Model.BusinessUnit.Address1TypeCode" floatLabelType="Auto">
      <e-dropdownlist-fields text="Text" value="Value"></e-dropdownlist-fields>
</ejs-dropdownlist>

Model.BusinessUnit.Address1TypeCode has AddressTypeCode type.

The enum declaration:
public enum AddressTypeCode {
        [Display(Name = "Facturar a")]
        BillTo,
        [Display(Name = "Enviar a")]
        ShipTo,
        [Display(Name = "Principal")]
        Primary,
        [Display(Name = "Otra")]
        Other }

On load get empty value:    
<select aria-hidden="true" tabindex="-1" class="e-ddl-hidden" name="BusinessUnit.Address1TypeCode" id="Address1TypeCode_hidden" data-val="true">
      <option selected="" value="2">null</option>
</select>
<input id="Address1TypeCode" data-val="false" ejs-for="true" class="e-control e-dropdownlist e-lib" role="textbox" type="text" aria-labelledby="label_Address1TypeCode" readonly="" style="" aria-disabled="false" aria-label="undefined" tabindex="-1">
 
But datasource is correct:
new ejs.dropdowns.DropDownList({
  "dataSource": ejs.data.DataUtil.parse.isJson([
  {
    "Disabled": false,
    "Group": null,
    "Selected": false,
    "Text": "Facturar a",
    "Value": "0"
  },
  {
    "Disabled": false,
    "Group": null,
    "Selected": false,
    "Text": "Enviar a",
    "Value": "1"
  },
  {
    "Disabled": false,
    "Group": null,
    "Selected": false,
    "Text": "Principal",
    "Value": "2"
  },
  {
    "Disabled": false,
    "Group": null,
    "Selected": false,
    "Text": "Otra",
    "Value": "3"
  }
]),
  "fields": {
    "text": "Text",
    "value": "Value"
  },
  "floatLabelType": "Auto",
  "ignoreAccent": false,
  "placeholder": "Tipo",
  "popupHeight": "auto",
  "value": 2,
  "zIndex": 1000.0
}).appendTo("#Address1TypeCode");

Could you help me? What is wrong?


3 Replies 1 reply marked as answer

JM Jeyanth Muthu Pratheeban Sankara Subramanian Syncfusion Team March 29, 2021 12:30 PM UTC

Hi Jesús,

Thanks for contacting Syncfusion support. 

We have checked your query of predefined value not setting to the control when Enum datasource is provided. We would like to thank you for sharing your observations of datasource generation and DOM elements which helped us to understand your query much better. On further analysis of the shared information, we suspect that Dropdownlist’s generated value in datasource is of String type (Value = “2”) whereas provided predefined value is of int type (Value = 2)


 
new ejs.dropdowns.DropDownList({
  "dataSource": ejs.data.DataUtil.parse.isJson([
   {
    "Disabled": false,
    "Group": null,
    "Selected": false,
    "Text": "Principal",
    "Value": "2"
  },
 ]),
  "fields": {
    "text": "Text",
    "value": "Value"
  },
  "floatLabelType": "Auto",
  "ignoreAccent": false,
  "placeholder": "Tipo",
  "popupHeight": "auto",
  "value": 2,
  "zIndex": 1000.0
}).appendTo("#Address1TypeCode"); 
 
Therefore, we suggest you to set the value property is of string type. We have made sample for your convenience. Please refer the below sample and get back to us if you need any further assistance on this.

Sample Link       : https://www.syncfusion.com/downloads/support/directtrac/general/ze/Dropdownlist_Enum1013473623
 
 
Screenshot        : 
 
 
 
Regards, 
Jeyanth. 


Marked as answer

JM Jesús Mostajo March 29, 2021 01:41 PM UTC

Great, with your suggestions work fine!

Finally, I've changed dropdownlist datasource, converting to integer the enumeration value:

 <ejs-dropdownlist id="Address1TypeCode" placeholder="@Html.DisplayNameFor(m => m.BusinessUnit.Address1TypeCode)" popupHeight="auto"
                                                  dataSource="@Html.GetEnumSelectList<AddressTypeCode>().Select(a => new { a.Text, Value = Convert.ToInt16(a.Value) })" ejs-for="@Model.BusinessUnit.Address1TypeCode" floatLabelType="Auto">
                                    <e-dropdownlist-fields text="Text" value="Value"></e-dropdownlist-fields>
                                </ejs-dropdownlist> 

Thanks !!


JM Jeyanth Muthu Pratheeban Sankara Subramanian Syncfusion Team March 30, 2021 06:00 AM UTC

Hi Jesús 

We are glad to hear that your issue has been resolved. Please let us know if you need any further assistance on this. 

Regards, 
Jeyanth. 


Loader.
Up arrow icon