<SfDropDownList TValue="string" TItem="EmployeeData" Placeholder="Select a customer" Query="@Query">
<DropDownListTemplates TItem="EmployeeData">
<ItemTemplate>
<span><span class='name'>@((context as EmployeeData).FirstName)</span><span class='country'>@((context as EmployeeData).Country)</span></span>
</ItemTemplate>
</DropDownListTemplates>
<SfDataManager Url="https://ej2services.syncfusion.com/production/web-services/api/Employees" Adaptor="Syncfusion.Blazor.Adaptors.WebApiAdaptor" CrossDomain="true"></SfDataManager>
<DropDownListFieldSettings Text="FirstName" Value="Country"></DropDownListFieldSettings>
</SfDropDownList>
But how do we make it work with Enums? Nothing is happening when ItemTemplate is used here:
<SfDropDownList TValue="Values" TItem="string" Placeholder="e.g. Australia" DataSource="@EnumValues" @bind-Value="@ddlVal">
<DropDownListTemplates TItem="string">
<ItemTemplate context="country">
<span>Hello @country</span>
</ItemTemplate>
</DropDownListTemplates>
</SfDropDownList>
So the solution is to define the list of values as the name of the enum value, and not the enum itself.
This is a poor solution but at least it will work. Why can't we bind to the typed enum value direct though?
It's is possible to user DropDownList with enums and a TEMPLATE
follow the example:
declare the DataSource:
The GetDisplayName() is an extension method to Get the Display (name) of Enum
I'm posting another solution, as the past one (With Template) doesn't seems to work anymore
First create a List of KeyValuePair from the Enum:
them create your dropdown list as:
Thank you for sharing the alternative solution. We appreciate your contribution. If you have any more questions or need further assistance, please let us know.