I want to add items to the dropdown list after the inital load (see the simplified example below)
Though the data source has changed, the dropdown list is not showing the new item(s)
How can you force to update the displayed items?
<DropDownList @bind-SelectedValues=”@DropDownListBoxValue” DataSource=”@DataSource”>
</DropDownList>
<br />
<h3>DropDownList selected value: @DropDownListBoxValue[0] </h3>
<br />
<button type=”button” class=”btn btn-primary” @onclick=”AddItem”>Add item</button>
@code {
public List<string> DataSource = new List<string>()
{
“Item 1”,
“Item 2”,
“Item 3”,
“Item 4”
};
public string[] DropDownListBoxValue = new string[] { “Item 3″ };
private void AddItem()
{
int nNewItem = DataSource.Count + 1;
DataSource.Add($”Item {nNewItem}”);
// Are further steps needed to refresh the dropdown list?
}
}