Problem With Change and ValueChange on SfDropDownList

Hello,

I am trying to do a cascading dropdown, but I am having trouble activating the change event for the first  SfDropDownList.

I have made a code snippet to try and see wich event fires, but none of them did.

Could you tell me what am I doing wrong?

Regards,

Alexandre


@page "/test-dropdown"

@using Syncfusion.Blazor.DropDowns

@using FrotiXBlazorMaui.Shared


<SfDropDownList TValue="string" TItem="SelectListItemModel"

                DataSource="@Items"

                Placeholder="Selecione um item"

                Value="@SelectedValue"

                ValueChange="OnValueChange"

                Change="OnChange">

    <DropDownListFieldSettings Text="Text" Value="Value"></DropDownListFieldSettings>

</SfDropDownList>


<p>Valor Selecionado: @SelectedValue</p>


@code {

    private List<SelectListItemModel> Items = new List<SelectListItemModel>

    {

        new SelectListItemModel { Text = "Item 1", Value = "Item1" },

        new SelectListItemModel { Text = "Item 2", Value = "Item2" },

        new SelectListItemModel { Text = "Item 3", Value = "Item3" }

    };


    private string SelectedValue { get; set; } = string.Empty;


    private async Task OnValueChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, SelectListItemModel> args)

    {

        SelectedValue = args.Value;

        Console.WriteLine($"ValueChange disparado: {args.Value}");

        await Task.CompletedTask;

    }


    private async Task OnChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, SelectListItemModel> args)

    {

        SelectedValue = args.Value;

        Console.WriteLine($"Change disparado: {args.Value}");

        await Task.CompletedTask;

    }


}



3 Replies 1 reply marked as answer

YS Yohapuja Selvakumaran Syncfusion Team March 19, 2025 11:23 AM UTC

Hi Alexandre

Thank you for reaching out to us.

We have reviewed your requirement, and we would like to inform you that the ValueChange event should be used inside the <DropDownListEvents> tag to handle value changes in the DropDownList. Please refer to the documentation below for more details on handling events:

Documentationhttps://blazor.syncfusion.com/documentation/dropdown-list/selection#valuechange-event

You can implement it as shown in the following example:

            <SfDropDownList TItem="Country" TValue="string" Placeholder="Select a country" DataSource="@Countries" @bind-Value="SelectedCountry">
                <DropDownListEvents TItem="Country" TValue="string" ValueChange="OnCountryChange"></DropDownListEvents>
                <DropDownListFieldSettings Text="CountryName" Value="CountryId"></DropDownListFieldSettings>
            </SfDropDownList>


Samplehttps://blazorplayground.syncfusion.com/BtLytUWaqxCHabaw

For further reference, please review the following demo and documentation:

Demohttps://blazor.syncfusion.com/demos/dropdown-list/cascading?theme=fluent2

Documentationhttps://blazor.syncfusion.com/documentation/dropdown-list/cascading



Regards,

Yohapuja S



Marked as answer

AL Alexandre March 20, 2025 08:49 PM UTC

Thank you!

I will try to make this solution work on my project.


Regards,


Alexandre



SS Shereen Shajahan Syncfusion Team March 21, 2025 05:01 AM UTC

Hi Alexandre,

We are marking this forum as solved. Please get back to us for assistance in the future.

Regards,

Shereen


Loader.
Up arrow icon