I am trying to set Value or SelectedIndex based on the datasource return after Read.
This is my View
@(Html.Kendo().DropDownList.
Name("ddlUsers").
DataTextField("text").
HtmlAttributes(New With {.style = "width:500px"}).
DataValueField("id").
DataSource(Sub(s)
s.Read(Sub(r) r.Action("GetUserList", "Employees")
End Sub). ServerFiltering(True)
End Sub).Events(Sub(e) e.Change("SetHiddenUGID")) )
The method GetUserList looks like this
Shared Function GetUserList() As IList
Return db.GetDBUserList().Where(Function(w) w.value <> 0).Select(Function(s) New With {.id = s.value,.text = s.text,.isdefault = s.isdefault}).ToList()
End Function
Now GetDBUserList returns a List of Employees
Public Class Employees
Public Property value As Int64
Public Property text As String
Public Property isdefault As Int32
End Class
I want to set the default value of the dropdown based on isdefault when it's 1, any ideas?
I have tried
var dropdownlist = $("#ddlUsers").data("kendoDropDownList");
dropdownlist.select(function (dataItem) {
if (dataItem.isdefault === 1) {
$("#ddlUsers").data("kendoDropDownList").value(dataItem.id);
}
});
But it did not work.
@model MyModel
at the top) – Matt Millican