Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
148929 | Nov 8,2019 03:28 AM UTC | May 20,2020 06:31 AM UTC | Blazor | 8 |
![]() |
Tags: Dropdown List |
@using Syncfusion.EJ2.Blazor.DropDowns
@using BlazorApp1.Data;
@inject DropDownData dropdownService
<EjsDropDownList TValue="string" @bind-Value="@DropVal" DataSource="@listData">
<DropDownListFieldSettings Value="ID" Text="Text"></DropDownListFieldSettings>
</EjsDropDownList>
@code {
public string DropVal { get; set; }
List<Games> listData = new List<Games>();
protected async override Task OnInitializedAsync()
{
listData = await dropdownService.getData();
DropVal = listData[0].ID;
}
} |
<EjsDropDownList TValue="string" DataSource="@listData" Index="0">
<DropDownListFieldSettings Value="ID" Text="Text"></DropDownListFieldSettings>
</EjsDropDownList> |
Okay, I vouch the issue is because the items aren't populated yet. There's a workaround though, you need to create a new component put the EjsDropDownList in there and put the service inside the OnInitializedAsync(). There's must be [Parameter] that connects to @bind-Value.The wrapper component is the one that will use:<DropDownListDepartments SelectedValue="@selectedVal"></DropDownListDepartments>
protected override async Task OnInitializedAsync()
{
DataSource = await ownservice.GetDataAsync();
this.val = await ownservice.GetPreSelectDataAsync();
}
|
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.