We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Getting Dropdown List to reflect canging data source

I have a drop down list whose datasource is updated from another control. The dropdown list is part of a trio of cascading dropdowns. 


I call RefreshDataAsync to update the dropdowns datasource having changed it from the other control.   I can make the dropdown reflect the datasource change by refreshing the entire page using  uriHelper.NavigateTo(uriHelper.Uri, forceLoad: true); but that obviously looses state of all controls on the page which is not desirable. 


Is there a better way to do this so state is not lost on the other controls on the page (like calling StaeHasChanged from the dropdown whose datasource has changed?  


Many thanks in advance


3 Replies

PK Priyanka Karthikeyan Syncfusion Team April 5, 2023 05:06 PM UTC

Hi Martin,


To achieve your requirement, you can change the data source and re-render the dropdown list component when the button is clicked. Please see the following code snippet:


<SfButton @onclick="onClick">Click</SfButton>

 

@if (ButtonValue)

 

{

    <SfDropDownList TItem="GameFields" TValue="string" PopupHeight="230px"  Placeholder="e.g. Basketball" @bind-Value="@DropDownValue" DataSource="@Games">

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

    </SfDropDownList>

}

private async Task onClick(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)    {

      this.ButtonValue = false;

       this.Games = new List<GameFields>()

    {

        new GameFields(){ ID= "Game1", Text= "Football" },

        new GameFields(){ ID= "Game2", Text= "Badminton1" },

        new GameFields(){ ID= "Game3", Text= "Throwball" },

        new GameFields(){ ID= "Game10", Text= "Tennis"}

    };

       await Task.Delay(10);

       this.ButtonValue = true;

}


For further details, please check the attached sample.


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


Regards,

Priyanka K



Attachment: DropdownlistSample_839c0375.zip


MA Martin April 6, 2023 12:23 PM UTC

Many thanks, that worked.


I would never have thought of forcing rerender that way!



DR Deepak Ramakrishnan Syncfusion Team April 7, 2023 04:22 PM UTC

Hello Martin,


We are delighted to hear that your requirement has been fulfilled. Please do not hesitate to contact us if you have any further queries.


Thanks,

Deepak R.


Loader.
Live Chat Icon For mobile
Up arrow icon