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

Can't choose the first item in dropdown on Kendo Grid colum foreignkey

1 Answer 130 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Csa asked on 14 May 2014, 05:45 AM
Hi All,

I am learning on Kendo grid features with MVC4 and EF5 db first.
I am able to use dropdown in kendo grid for update.
But found small issue with selecting the first item in the dropdown inside kendo grid when creating new record.
Step to reproduce:
1. "Add new record" then try to fill in the type as dropdownlist with the first item available.
2. When you get focus to the dropdownlist, it is showing the first item as default, but when you lost focus (without clicking any item), it will not fill in the grid with the first item from dropdown list.
3. Even if you try clicking on the first item from the dropdownlist, it is still not filling the grid with the first item.

It is working find if you selecting the second or thirds and so on. Only happened to the first item of the dropdownlist.
Please find the code in the attachment.
Any help will be much appreciated.

1 Answer, 1 is accepted

Sort by
Vladimir Iliev
Telerik team
answered on 15 May 2014, 12:03 PM
Hi Csa,

In current case you should either set the "OptionLabel" of the DropDownList editor ("GridForeignKey.cshtml" under the "EditorTemplates" folder) or set a default value for this field in the Model configuration (to be equal to the first item in the list). Please check the examples below:

1) Option 1 - Set the "OptionLabel" in "GridForeignKey.cshtml":
@model object
@(Html.Kendo().DropDownListFor(m => m)       
    .OptionLabel("- please select -")
    .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])

2) Option 2 - set the default value:
.DataSource(dataSource => dataSource       
    .Model(model => {
        model.Id(p => p.OrderID);
        model.Field(p => p.OrderID).Editable(false);
        model.Field(p => p.EmployeeID).DefaultValue("1");     

Vladimir Iliev

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Asked by
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question