Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazorise Select Default Value

Tags:

blazorise

Is there a way to choose the default value from a list using the in Blazorise? Right now the default value is null, but I would like it to be say "3".

<Select @bind-SelectedValue="@_someProperty">

                                @foreach (string number in _numbers)
                                    {
                                    <SelectItem Value="@number ">@number </SelectItem>
                                    }
                            </Select>

@code
private static readonly string[] _numbers =
        {
            "1", "2", "3", "4", "5",
        };
like image 592
Katelyn Rochat Avatar asked Sep 12 '25 17:09

Katelyn Rochat


1 Answers

This is a simple approach to fix this (just add a variable with initial value). You can Also use SelectedValueChanged to manually handle your custom variable.

<Select @bind-SelectedValue="@_selectedProperty" SelectedValueChanged="@OnSelectedValueChanged">

                                @foreach (string number in _numbers)
                                    {
                                    <SelectItem Value="@number ">@number </SelectItem>
                                    }
                            </Select>

@code
{

private string _selectedProperty = 3;
private static readonly string[] _numbers =
        {
            "1", "2", "3", "4", "5",
        };

void OnSelectedValueChanged( string value )
{
    _selectedProperty = value; // Bind to the custom variable
    Console.WriteLine( selectedValue ); // Write in Console Just for Checking
}

}
like image 147
Ali Kianoor Avatar answered Sep 14 '25 13:09

Ali Kianoor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!