Answers for "set option as selected in blazor"

C#
2

blazor option selected

<select value="@SelectedYear" @onchange="ChangeYear">
    @for (int i = 2015; i < DateTime.Now.Year + 1; i++)
    {
        <option value="@i">@i</option>
    }
</select>

<p>@SelectedYear</p>

@code
 {
    private int SelectedYear { get; set; } = 2018;

    void ChangeYear(ChangeEventArgs e)
    {
        SelectedYear = Convert.ToInt32(e.Value.ToString());

    }
}
Posted by: Guest on December-29-2020

Code answers related to "set option as selected in blazor"

C# Answers by Framework

Browse Popular Code Answers by Language