I have two dropdown list. One is province and the other one is city. Data are downloaded from an API on OnInitializedAsync(). When province is selected, list of city is updated with a new list of cities with the help of
<DropDownListEvents TValue="string" ValueChange="OnChange" />
in province list. It works okay if manually selected with a mouse. But when programmatically selected because it's in edit mode, the province works fine but the city is not. The city list though is updated but the @bind-Value="@city" is not being selected thought the list is updated. Here's my code snippet:
<EjsDropDownList @ref="provinceObj" TValue="string" Placeholder="Province" DataSource="@provinces" @bind-Value="@provinceBindVal">
<DropDownListFieldSettings Value="id" Text="provinceName" />
<DropDownListEvents TValue="string" ValueChange="OnChange" />
</EjsDropDownList>
<EjsDropDownList @ref="cityObj" TValue="string" Placeholder="Cities" DataSource="@cities" @bind-Value="@cityDefaultValue">
<DropDownListFieldSettings Value="id" Text="cityName" />
</EjsDropDownList>
public void OnPopupOpen(PopupOpenEventArgs<object> args) {
cityDefaultValue2 = data.cityId.ToString();
provinceBindVal = data.provinceId.ToString();
}
private void OnChange(ChangeEventArgs<string> args)
{
for(int i = 0; i < provinces.Count(); i++)
if (int.Parse(args.Value) == int.Parse(provinces[i].id))
cities = provinces[i].provinceCities[0].cities;
if (isEditMode)
{
for (int i = 0; i < cities.Count(); i++)
{
if (cityDefaultValue2 == cities[i].id)
{
cityDefaultValue = cities[i].id;
break;
}
}
}
}
I have already added StateHasChanged() and Task.Delay(400), still not getting the correct city.