Before, the Value from the first item in the Data was populated through @bind-Value to the view model. It no longer is.
In the following snippet, I expect to see "1" in the initial load of the page, but I see "0" - the default value for the integer.
@selectedValue
<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" @bind-Value="@selectedValue">
</TelerikDropDownList>
@code {
//in a real case, the model is usually in a separate file
//the model type and value field type must be provided to the dropdpownlist
public class MyDdlModel
{
public int MyValueField { get; set; }
public string MyTextField { get; set; }
}
IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
int selectedValue { get; set; }
}
Hello Boštjan,
We have been reviewing this and we have found that the old behavior was never correct - the dropdownlist should not select the first item in the dropdown. It should be up to the application to determine what values are allowed and our old behavior was wrong. We will be aligning ours with the native InputSelect and the standard ways this is handled. You can preview the documentation about this here: https://github.com/telerik/blazor-docs/commit/79b2c24fbc3b71fc4e9afad5f271c879de38199b.
Regards,
Marin Bratanov
Progress Telerik
And here is a workaround
@selectedValue
<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" @bind-Value="@selectedValue">
</TelerikDropDownList>
@code {
//in a real case, the model is usually in a separate file
//the model type and value field type must be provided to the dropdpownlist
public class MyDdlModel
{
public int MyValueField { get; set; }
public string MyTextField { get; set; }
}
IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
int selectedValue { get; set; }
protected override void OnInitialized()
{
// workaround - set the value to the first item manually
// this is done in OnInitialized for brevity, do it after fetching the data for the first time
selectedValue = myDdlData.FirstOrDefault().MyValueField;
base.OnInitialized();
}
}
Regards,
Marin Bratanov
Progress Telerik
Indeed, this seems to have broken in 2.9.0, and seems to work in 2.8.0
Regards,
Marin Bratanov
Progress Telerik