Blazorise DropdownList component
The DropdownList component allows you to select a value from a list of predefined items.
To use the DropdownList component, install the Blazorise.Components package first.
Installation
Blazorise.Components NuGet package.
NuGet
Install extension from NuGet.dotnet add package Blazorise.Components
Imports
In your main_Imports.razor add:
@using Blazorise.Components
Example
<DropdownList TItem="Country" TValue="string" Data="" TextField="@(( item ) => item.Name)" ValueField="@(( item ) => item.Iso)" @bind-Value="" Color="Color.Primary" MaxMenuHeight="200px"> Select item </DropdownList> <Field Horizontal> <FieldBody ColumnSize="ColumnSize.Is12"> Selected item: @selectedDropValue </FieldBody> <FieldBody ColumnSize="ColumnSize.Is12"> Selected text: @Countries?.FirstOrDefault( x => x.Iso == @selectedDropValue )?.Name </FieldBody> </Field>
@code { private readonly CountryData CountryData = new(); public IEnumerable<Country> Countries; protected override async Task OnInitializedAsync() { Countries = await CountryData.GetDataAsync(); await base.OnInitializedAsync(); } string selectedDropValue { get; set; } = "CN"; }
Checkbox Selection
The multiple selection feature in Blazorise's DropdownList component enables users to select multiple options from a dropdown menu via checkboxes. Each option in the menu comes with a checkbox for selection. Upon clicking the DropdownList, users can tick multiple checkboxes to select various options. This feature provides an efficient way of making multiple selections, enhancing user flexibility and interaction.<DropdownList TItem="Country" TValue="IReadOnlyList<string>" Data="" TextField="@(( item ) => item.Name)" ValueField="@(( item ) => item.Iso)" @bind-Value="" SelectionMode="DropdownListSelectionMode.Checkbox" Color="Color.Primary" MaxMenuHeight="200px"> Select item </DropdownList> <Field Horizontal> <FieldBody ColumnSize="ColumnSize.Is12"> Selected values: @(selectedDropValues is not null ? string.Join( ',', selectedDropValues ) : ""); </FieldBody> <FieldBody ColumnSize="ColumnSize.Is12"> Selected texts: @(selectedDropValues is not null ? string.Join( ',', selectedDropValues.Select( x => Countries.FirstOrDefault( country => country.Iso == x )?.Name ?? string.Empty )) : string.Empty ) </FieldBody> </Field>
@code { private readonly CountryData CountryData = new(); public IEnumerable<Country> Countries; protected override async Task OnInitializedAsync() { Countries = await CountryData.GetDataAsync(); await base.OnInitializedAsync(); } private IReadOnlyList<string> selectedDropValues { get; set; } = new[] { "AM", "AF" }; }
With Search
The DropdownList component in Blazorise allows users to search for items in the dropdown list.
By enabling Filterable property, a search box is displayed at the top of the dropdown list. Users can type in the search box to filter the list and quickly locate the desired item. This feature enhances user experience by providing a more efficient way of selecting items from a dropdown list.
<DropdownList TItem="Country" TValue="string" Data="" TextField="@(( item ) => item.Name)" ValueField="@(( item ) => item.Iso)" @bind-Value="" Color="Color.Primary" MaxMenuHeight="200px" Filterable> Select item </DropdownList> <Field Horizontal> <FieldBody ColumnSize="ColumnSize.Is12"> Selected item: @selectedDropValue </FieldBody> <FieldBody ColumnSize="ColumnSize.Is12"> Selected text: @Countries?.FirstOrDefault( x => x.Iso == @selectedDropValue )?.Name </FieldBody> </Field>
@code { private readonly CountryData CountryData = new(); public IEnumerable<Country> Countries; protected override async Task OnInitializedAsync() { Countries = await CountryData.GetDataAsync(); await base.OnInitializedAsync(); } string selectedDropValue { get; set; } = "CN"; }
API
See the API reference for the parameters, events, methods, and related types available to the components covered on this page.