@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();
}
|