Blazored Typeahead import value selected from database

1.9k views Asked by At

How do i set the selected value in the product list when editing?

<Blazored.Typeahead.BlazoredTypeahead SearchMethod="RicercaCategoria" 
                                      @bind-Value="categoriaSelezionato" 
                                      EnableDropDown="false" 
                                      Placeholder="Scegli o aggiungi la Categoria">
    <SelectedTemplate>@context.NomeCategoria</SelectedTemplate>
    <ResultTemplate>@context.NomeCategoria</ResultTemplate>
</Blazored.Typeahead.BlazoredTypeahead>

From a list I get the categories to see. From a database instead I recover the record that interests me

1

There are 1 answers

2
Steve Greene On

You need to setup an event to do that. You have to modify your syntax slightly as described in the documentation:

Replace your @bind-Value with (guessing at class names):

Value="categoriaSelezionato"
ValueChanged="@( (Categoria c) => SelectedCategoriaChanged(c) )"
ValueExpression="@( () => categoriaSelezionato )"

You may also need TValue and TItem, but I did not.

Then handle the event:

private void SelectedCategoriaChanged(Categoria categoria )
{
     // Use the selected record however needed


     // Set your Value so it shows:
     categoriaSelezionato = categoria;
}