|
@using Syncfusion.Blazor.DropDowns
@using Newtonsoft.Json
<SfComboBox TValue="int" TItem="Countries" PopupHeight="230px" Placeholder="Land auswählen" Value="@value" DataSource="@Country">
<ComboBoxEvents TValue="int" ValueChange="onCountryIDChanged"></ComboBoxEvents>
<ComboBoxFieldSettings Text="Name" Value="CountryID"></ComboBoxFieldSettings>
</SfComboBox>
@code {
public int value { get; set; } = 4;
public class Countries
{
public string Name { get; set; }
public int CountryID { get; set; }
}
List<Countries> Country = new List<Countries>
{
new Countries() { Name = "Australia", CountryID = 1 },
new Countries() { Name = "Bermuda", CountryID = 2 },
new Countries() { Name = "Canada", CountryID = 3 },
new Countries() { Name = "Cameroon", CountryID = 4 },
new Countries() { Name = "Denmark", CountryID = 5 },
new Countries() { Name = "France", CountryID = 6 },
new Countries() { Name = "Finland", CountryID = 7 },
new Countries() { Name = "Germany", CountryID = 8 },
new Countries() { Name = "Greenland", CountryID = 9 },
new Countries() { Name = "Hong Kong", CountryID = 10 },
new Countries() { Name = "India", CountryID = 11 },
new Countries() { Name = "Italy", CountryID = 12 },
new Countries() { Name = "Japan", CountryID = 13 },
new Countries() { Name = "Mexico", CountryID = 14 },
new Countries() { Name = "Norway", CountryID = 15 }
};
public void onCountryIDChanged(ChangeEventArgs<int> args)
{
var item = JsonConvert.DeserializeObject<Countries>(args.ItemData.ToString());
var value = item.CountryID;
var id = item.Name;
}
} |