Can't set the selected item in dropdownlist when using Async

Hi,

I have dropdown list that is bound to an IEnumerable retireved from a DB. The value that should be selected from the list is retreived in a second query. If the second query is Async then setting the selection fails. If the second query is not async it works fine. This looks pretty similar to an ThreadId 148929.

                        <SfDropDownList TValue="int?" DataSource="DashBoards" Width="200px" TItem="DashBoard" Value="DashBoardId" @ref="ddlDashBoards">
                            <DropDownListFieldSettings Value="DashBoardId" Text="Name"></DropDownListFieldSettings>
                            <DropDownListEvents  OnValueSelect="OnValueSelectDashBoardListAsync" TValue="int?" TItem="DashBoard"></DropDownListEvents>
                            <DropDownListTemplates TItem="DashBoard">
                                <!-- Templated to allow the inclusion of the shared icon -->
                                <ItemTemplate>
                                    @{
                                        var DashBoardObj = (context as DashBoard);
                                        if (DashBoardObj != null)
                                        {
                                            if (DashBoardObj.AccessType == DashBoardAccess.Access.Shared)
                                            {
                                                <span class="vx-icon-share"></span>
                                                <span>@DashBoardObj.Name</span>
                                            }
                                            else
                                            {
                                                <span style="padding-left:27px;">@DashBoardObj.Name</span>
                                            }
                                        }
                                    }
                                </ItemTemplate>
                                <ValueTemplate>
                                    @{
                                        var DashBoardObj = (context as DashBoard);
                                        if (DashBoardObj != null)
                                        {
                                            if (DashBoardObj.AccessType == DashBoardAccess.Access.Shared)
                                            {
                                                <div style="margin-top: 4px; margin-left: 8px;">
                                                    <span class="vx-icon-share"></span>
                                                    <span>@DashBoardObj.Name</span>
                                                </div>
                                            }
                                            else
                                            {
                                                <div style="margin-top: 5px; margin-left: 8px;">
                                                    @DashBoardObj.Name
                                                </div>
                                            }
                                        }
                                    }
                                </ValueTemplate>
                            </DropDownListTemplates>
                        </SfDropDownList>


        protected override async Task OnInitializedAsync()
        {
            this.DashBoards = await this.DashBoardRepositoryObj.GetDashBoardsAsync();

            // Get the last selected dashboard. If its null (first time in)  or its been delete then use default vale
            // UserPreference UserPreferenceObj = await this.UserRepositoryObj.GetUserPreferenceAsync(UserPreference.DASHBOARDSELECTED, ApplicationConfigurationObj.LoggedUserId);
            UserPreference UserPreferenceObj = this.UserRepositoryObj.GetUserPreference(UserPreference.DASHBOARDSELECTED, ApplicationConfigurationObj.LoggedUserId);

            if (UserPreferenceObj.NumericValue != null && (this.DashBoards.FirstOrDefault<DashBoard>((DashBoard x) => x.DashBoardId == UserPreferenceObj.NumericValue) != null))
                this.DashBoardId = UserPreferenceObj.NumericValue;
            else
                // Make the first Dashboard in the list the selected one
                this.DashBoardId = this.DashBoards.First<DashBoard>().DashBoardId;
        }

Regards,
Mike

3 Replies 1 reply marked as answer

SP Sureshkumar P Syncfusion Team October 28, 2020 08:04 AM UTC

Hi Michael, 
 
Greetings from Syncfusion support. 
 
Based on your shared information. we have checked the previously updated sample in the #148929 with our latest version. We would like to say this the second query (setting the value property) is updated based on the function return type. When you use the async function you need to get the value as await method. If you do not return as async method, then you no need to get the value as await. We suspect your application is works based on getting functions return type.  
 
 
If still you have facing the issue, then please replicate the facing issue in the above attached sample and revert us with detailed issue replication steps. That will help us to provide exact solution as earlier as possible. 
 
Regards, 
Sureshkumar P 


Marked as answer

MA Michael Aston October 28, 2020 01:13 PM UTC

Hi,

My mistake. Works fine when setting in OnParametersSetAsync.

Thanks
Mike


SP Sureshkumar P Syncfusion Team October 29, 2020 09:24 AM UTC

Hi Michael, 
 
Thanks for the update. 
 
Regards, 
Sureshkumar P 


Loader.
Up arrow icon