I'm using TelerikDropDownList and i want to set selectbox value by external code (manually, without the user interface) by an event.
<TelerikDropDownList Id="TelerikDropDownListId"
@bind-Value="@Model.Id"
Data="@DataDropDownList"
ValueField="Value"
TextField="Text"
@ref="TelerikDropDownListId"/>
<button @onclick="ChangeSelectBoxValue" />
@code {
public List<DropDownItem<long>> DataDropDownList = new List<DropDownItem<long>>();
private void ChangeSelectBoxValue()
{
DataDropDownList.Add(new DropDownItem<long>() { Value = 0, Text = "(New)" });
TelerikDropDownListId.TextField = "(New)";
TelerikDropDownListId.Value = 0;
StateHasChanged();
}
}
You need to add the new item in the list, but change the value that you pass in
@bind-Valueand not changing the value of the component ref.