I have a grid which shows employee data and enable user to edit the data. When edit command is pressed, it displays dropdown list for one of the column(Name). The dropdown value gets displayed without any issue however when edit command is pressed, the existing value within the dropdown gets hidden and first value '- Select -....' get displayed.
P.S: i followed this tutorial to add dropdown in Kendo Grid: http://www.sitereq.com/post/kendo-mvc-dropdown-lists-inside-inline-kendo-mvc-grids
Code Behind:
class
EmployeeItem
{
public
string
Name{
get
;
set
;}
public
string
Code1{
get
;
set
;}
public string Code2{get;set;}
public
string
CombinedValues{
get
;
set
;}
//this is combination of Name, Code1, Code2 delimited by comma
}
Controller Code:
List<EmployeeItem> employeeList = service.GetEmployeeList();
ViewBag.EmployeeList =
new
SelectList(employeeList,
"CombinedValues"
,
"Name"
);
EditorTemplate Code (_EmployeeDropDown.cshtml):
@(Html.Kendo().DropDownList()
.BindTo((IEnumerable)ViewBag.EmployeeList)
.OptionLabel("- Select - ")
.DataValueField("Value")
.DataTextField("Text")
.Name("EmployeeData")
)
View Code:
@(Html.Kendo().Grid(Model.employeeDetails)
.Name("GridEmployeeDetails")
.Columns(columns =>
{
columns.Command(command => { command.Edit(); }).Width("180px").Title("Action");
columns.Bound(e => e.Name).Width("210px").EditorTemplateName("_EmployeeDropDown")
.ClientTemplate("#:EmployeeData#");
})
So if the employeeList have values something like this:
Name = John, Code1 = 1, Code2 = 2, CombinedValues = John,1,2
Name = Matt, Code1 = 21, Code2 = 50, CombinedValues = Matt, 21, 50
In the grid, when i first view the grid it displays the Name, John in first row, Matt in second row. If i edit Matt row, the dropdown will show up with '-Select-' as selected value instead of 'Matt'.
Does anyone know how i can achieve that?
Also, once i make selection on dropdown, let's say from Matt to John, and hit inline Save button now the value changes to CombinedValues i.e. John,1,2 instead of just John under Name column.