Skip to main content Skip to footer

How to handle a selected item with AutoComplete

To add auto complete to your Blazor input, you could use the SelectedValueChanged EventCallback to process when a selection change has been made. Refer to the following code snippet:

<C1AutoComplete ItemsSource="countries" T="Country" SelectedValueChanged="OnSelectedValueChanged" Dropdown />

@code
{
    IEnumerable<Country> countries;

    protected void OnSelectedValueChanged(object country)
    {
        Country selectedCountry = (Country)country;
        string countryName = selectedCountry.Name;
        Console.WriteLine(countryName);
    }

    protected override void OnInitialized()
    {
        countries = Country.GetCountries();
    }
}