1

Here is my Entity Edit Page Code,

@(Html.Kendo().DropDownListFor(x => x.ParentCategoryId).Name("ParentCategoryId").HtmlAttributes(new { style = "width:300px;" }).DataTextField("Name").Value("ID").DataValueField("ID")
                      .DataSource(source => { source.Read(read => { read.Action("GetCategory", "Category"); }); }))

and i want to set dropdownlist selected item by Model.ParentCategoryId

is it possible dropdownlist.selectedvalue = Model.ParentCategoryId ?

Dursun ICCAN
  • 69
  • 1
  • 9
  • yes you are right binding is well. But, in my editpview i want to select item in kendo dropdownlist by model.ParentCategoryId ? – Dursun ICCAN Feb 25 '14 at 18:36

1 Answers1

1

If you want to change the selected item in the dropdown, you need to give the dropdown some information so it knows what item to select from its data binding.

A simple javascript approach might be:

var dropdownlist = $("#dropdownlist").data("kendoDropDownList");

dropdownlist.select(function(dataItem) {
    return dataItem.text === "SomeStringToMatchUp";
});

In your case, you would use .value instead of .text. I don't really use your method, so you might actually have to set dataItem.SomeName for this approach to work.

If you want to set the default selection, one approach of several valid tactics is to set it after = databinding is complete (event)

EDIT: Here is another similar thread which you should reference. Remember that search is your best friend!

Community
  • 1
  • 1
Ray
  • 1,422
  • 2
  • 21
  • 39
  • $(document).ready(function () { var dropdownlist = $("#KendoDDL").data("kendoDropDownList"); dropdownlist.select(function (dataItem) { return dataItem.Name === "isim0"; }); }); i tried like this and didn't word :( – Dursun ICCAN Feb 25 '14 at 19:27
  • You might want to do some JS debugging and peek inside your DDL and var dropdownlist to see if it is populating correctly. Also make sure that your – Ray Feb 25 '14 at 20:27