@page "/Test"
<SfComboBox TValue="Car" TItem="Car" PopupHeight="230px" Width="200px" AllowCustom="false" Autofill="true" Placeholder="Car" @bind-Value="@SelectedCar" DataSource="@Cars">
<ComboBoxFieldSettings Text="Name" Value="Id"></ComboBoxFieldSettings>
</SfComboBox>
<SfButton Content="Test" @onclick="@Onlick"></SfButton>
@code {
public List<Car> Cars { get; set; }
public Car SelectedCar { get; set; }
protected override async Task OnInitializedAsync()
{
Cars = new List<Car>
{
new Car
{
Id = 1,
Model = "Audi",
Make = "A4"
},
new Car
{
Id = 2,
Model = "VW",
Make = "Beetle"
},
new Car
{
Id = 3,
Model = "Ford",
Make = "Focus"
},
};
}
private async Task Onlick(MouseEventArgs arg)
{
if (SelectedCar == null)
throw new Exception("No Car selected");
}
public class Car
{
public int Id { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public double MaxSpeed { get; set; }
public string Name => Model + " - " + Make;
}
}
|
@using Syncfusion.Blazor.DropDowns
<SfComboBox TValue="int" TItem="Car" PopupHeight="230px" Width="200px" AllowCustom="false" Autofill="true" Placeholder="Car" @bind-Value="@SelectedCar" DataSource="@Cars">
<ComboBoxFieldSettings Text="Name" Value="Id"></ComboBoxFieldSettings>
</SfComboBox>
<SfButton Content="Test" @onclick="@Onlick"></SfButton>
@code {
public List<Car> Cars { get; set; }
public int SelectedCar { get; set; }
protected override async Task OnInitializedAsync()
{
Cars = new List<Car>
{
new Car
{
Id = 1,
Model = "Audi",
Make = "A4"
},
new Car
{
Id = 2,
Model = "VW",
Make = "Beetle"
},
new Car
{
Id = 3,
Model = "Ford",
Make = "Focus"
},
};
}
private async Task Onlick(MouseEventArgs arg)
{
if (SelectedCar == null)
throw new Exception("No Car selected");
}
public class Car
{
public int Id { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public double MaxSpeed { get; set; }
public string Name => Model + " - " + Make;
}
}
|
|
<SfComboBox TValue="Car" TItem="Car" PopupHeight="230px" Width="200px" AllowCustom="false" Autofill="true" Placeholder="Car" @bind-Value="@SelectedCar" DataSource="@Cars">
<ComboBoxFieldSettings Text="Name" Value="Id"></ComboBoxFieldSettings>
</SfComboBox>
<SfButton Content="Test" @onclick="@Onlick"></SfButton>
@code {
public List<Car> Cars { get; set; }
public Car SelectedCar { get; set; }
protected override async Task OnInitializedAsync()
{
Cars = new List<Car>
{
new Car
{
Id = 1,
Model = "Audi",
Make = "A4"
},
new Car
{
Id = 2,
Model = "VW",
Make = "Beetle"
},
new Car
{
Id = 3,
Model = "Ford",
Make = "Focus"
},
};
}
private async Task Onlick(MouseEventArgs arg)
{
if (SelectedCar == null)
throw new Exception("No Car selected");
}
public class Car
{
public int Id { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public double MaxSpeed { get; set; }
public string Name => Model + " - " + Make;
}
} } |