I am using a 'Telerik UI for ASP.NET Core' DropDownList. The datasource is requesting a list of SelectItems where one of the item has the Selected
value on true
. My guess is the right behaviour would be for the item to be automatically selected but it is not.
Dropdownlist:
@(Html.Kendo().DropDownList()
.Name("CategoryId")
.DataSource(ds => ds.Read(read => read.Action("GetQuestionCategories", "Questions").Data("getParentCategoryId")).ServerFiltering(true))
.DataValueField("Value")
.DataTextField("Text")
.Events(events => events.Change("reloadLearningObjectives"))
.HtmlAttributes(new { @class = "form-control wide-full" })
)
The json text it is requesting:
[{"Disabled":false,"Group":null,"Selected":false,"Text":"Algemeen","Value":"62357618-ac53-4092-86d1-6c583b286bbe"},{"Disabled":false,"Group":null,"Selected":false,"Text":"Ballonvaren","Value":"9489c310-7549-45c7-a518-43f8016b2c3b"},{"Disabled":false,"Group":null,"Selected":false,"Text":"Paramotor","Value":"78d1a658-93f1-4eca-8b75-ad4bd4d33ef1"},{"Disabled":false,"Group":null,"Selected":false,"Text":"Part 66","Value":"b7b5845a-e2e0-45be-ad55-002180f8360b"},{"Disabled":false,"Group":null,"Selected":false,"Text":"ROC-Light","Value":"84ddea95-bda6-46b3-9660-2383d46033a0"},{"Disabled":false,"Group":null,"Selected":true,"Text":"Zweefvliegen","Value":"7367e8ff-d4a6-4766-b6b8-59f24f6e7b08"}]
As you can see the last item has "Selected" to true
but when the page is done loading it still says that an item needs to be selected.
You can use the dataBound event, and set the value of the widget there using the value() method , reference code sample :
So you can try to modify above code sample to meet your requirement :
dataBound: function(e) {
// handle the event
$.each(e.sender.dataSource._data, function (key, value) {
if(value.Selected==true){
e.sender.value(value.Value);
}
});
},