@page "/"
@using Syncfusion.Blazor.DropDowns
<div style="margin:130px auto;width:300px">
<SfDropDownList TValue="string" Placeholder=@PlaceHolderValue FloatLabelType="Syncfusion.Blazor.Inputs.FloatLabelType.Auto" TItem="Countries" DataSource="@Country" ShowClearButton="true" Width="300px">
<DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings>
<DropDownListEvents TItem="Countries" TValue="string" ValueChange="@ValueChangeHandler"></DropDownListEvents>
</SfDropDownList>
</div>
@code {
public string PlaceHolderValue { get; set; } = "Select
Country";
public class Countries
{
public string Name { get; set; }
public string Code { get; set; }
}
List<Countries> Country = new List<Countries>
{
new Countries() { Name = "Australia", Code = "AU" },
new Countries() { Name = "Bermuda", Code = "BM" },
new Countries() { Name = "Canada", Code = "CA" },
new Countries() { Name = "Cameroon", Code = "CM" },
};
private void ValueChangeHandler(ChangeEventArgs<string, Countries> args)
{
PlaceHolderValue = args.Value
!= null ? "Country" : "Select
Country";
}
}
|