This is a migrated thread and some comments may be shown as answers.

Property selected in SelectedListItem is not working after pass it to DDL control

1 Answer 57 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Mateusz
Top achievements
Rank 1
Mateusz asked on 15 Dec 2015, 09:02 AM

Hi 

I have DropDownList control which looks: 

@(Html.Kendo().DropDownListFor(m => m.VatCategoryId)
               .Name("VatCategoryId")
               .DataTextField("Text"
               .DataValueField("Value")
               .AutoBind(false)
               .DataSource(source =>
               {
                   source.Read(read =>
                   {
                       read.Action("GetVatCategoriesDefault", "VAT").Data("getCountry").Type(HttpVerbs.Get);
                   });
               })

In read method I am passing a list with categories. Some I want one of the item be selected. So I set property Selected = true in SlectedListItem. 

Data which view is receiving are good but the default category is not selected. 

What could be wrong? 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 16 Dec 2015, 04:15 PM
Hello Mateusz,

I am afraid that the DropDownList cannot directly communicate with the dynamically assigned datasource and read the object's list properties (selected in this case) and perform action base on their values.
 
This is why, I would suggest you to handle the dataBound event of the control an iterate though the items collection, in order to find the item with the Selected property set to true and set it as selected.

Regards,
Nencho
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DropDownList
Asked by
Mateusz
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or