I have the requirement to load a set of data in kendo grid editable cell in a dropdown list. The model which I have used to populate the
kendo grid Sales and the model that will be used for the dropdown is resource.
I have added the client template to the resource field
columns.Bound(p=> p.Resource).ClientTemplate("#=Resource.DisplayName#").Width(150);
model.Field(p=> p.Resource).DefaultValue(ViewData["defaultCategory"] as FOO.Models.ResourceModel);
But the above lines shows converting type error in view itself.
I have followed the procedures in the below link
http://demos.kendoui.com/web/grid/editing-custom.html
I have my view, controller code below. Can anyone help me out how to solve this.. or is there any other way is there to populate the kendo dropdown
in the kendo grid cell ?
View
@(Html.Kendo().Grid<FOO.Models.Sales>()
.Name("SalesGrid")
.Columns(columns =>
{
columns.Bound(p => p.ID);
columns.Bound(p =>p.Resource).ClientTemplate("#=Resource.DisplayName#").Width(150);
columns.Bound(p =>p.Customer).Width(150);
columns.Bound(p => p.GS).Width(150);
columns.Bound(p =>p.Price).Width(150);
})
.Scrollable()
.Editable(editable => editable.Mode(GridEditMode.InCell))
.HtmlAttributes(new { @style = "Font:12px calibri; " })
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetSaleDetailsByID", "Sales")
.Data("GetSaleByID")
)
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.Resource);
model.Field(p =>p.Resource).DefaultValue( ViewData["defaultCategory"] as FOO.Models.ResourceModel);
model.Field(p => p.Customer);
model.Field(p => p.GS).Editable(false);
model.Field(p => p.Price);
})
)
)
Controller
public ActionResult AppointmentSales()
{
PopulateCategories();
var id = RouteData.Values["id"];
EditSales oresult = new EditSales();
ViewData["appid"] = "";
if (id != null)
{
oresult = GetSalesDetails(id);
ViewData["appid"] = id;
}
return View(oresult);
}
CODE FOR POPULATING THE VIEW DATA
private void PopulateCategories()
{
var categories = _Sales.GetEmployees()
.Select(c => new ResourceModel
{
ID = c.ID,
DisplayName =c.DisplayName
})
.OrderBy(e => e.ID);
ViewData["categories"] =categories;
ViewData["defaultCategory"]= categories.First();
}
I have tried to populate a dropdown list box in kendo grid with the example given in kendo demos “Editing Custom editor”. But its not
working , it shows error in the view itself in the following set of line
model.Field(p =>p.Customer).DefaultValue(ViewData["defaultCategory"] as FOO.Models.ResourceModel);
and the error is
Cannot Convert from FOO.Models.ResourceModel to string
Can anyone help me out what is the mistake in the code ?
Mayil.M
On Behalf of
Jeremy Thompson
kendo grid Sales and the model that will be used for the dropdown is resource.
I have added the client template to the resource field
columns.Bound(p=> p.Resource).ClientTemplate("#=Resource.DisplayName#").Width(150);
model.Field(p=> p.Resource).DefaultValue(ViewData["defaultCategory"] as FOO.Models.ResourceModel);
But the above lines shows converting type error in view itself.
I have followed the procedures in the below link
http://demos.kendoui.com/web/grid/editing-custom.html
I have my view, controller code below. Can anyone help me out how to solve this.. or is there any other way is there to populate the kendo dropdown
in the kendo grid cell ?
View
@(Html.Kendo().Grid<FOO.Models.Sales>()
.Name("SalesGrid")
.Columns(columns =>
{
columns.Bound(p => p.ID);
columns.Bound(p =>p.Resource).ClientTemplate("#=Resource.DisplayName#").Width(150);
columns.Bound(p =>p.Customer).Width(150);
columns.Bound(p => p.GS).Width(150);
columns.Bound(p =>p.Price).Width(150);
})
.Scrollable()
.Editable(editable => editable.Mode(GridEditMode.InCell))
.HtmlAttributes(new { @style = "Font:12px calibri; " })
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetSaleDetailsByID", "Sales")
.Data("GetSaleByID")
)
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.Resource);
model.Field(p =>p.Resource).DefaultValue( ViewData["defaultCategory"] as FOO.Models.ResourceModel);
model.Field(p => p.Customer);
model.Field(p => p.GS).Editable(false);
model.Field(p => p.Price);
})
)
)
Controller
public ActionResult AppointmentSales()
{
PopulateCategories();
var id = RouteData.Values["id"];
EditSales oresult = new EditSales();
ViewData["appid"] = "";
if (id != null)
{
oresult = GetSalesDetails(id);
ViewData["appid"] = id;
}
return View(oresult);
}
CODE FOR POPULATING THE VIEW DATA
private void PopulateCategories()
{
var categories = _Sales.GetEmployees()
.Select(c => new ResourceModel
{
ID = c.ID,
DisplayName =c.DisplayName
})
.OrderBy(e => e.ID);
ViewData["categories"] =categories;
ViewData["defaultCategory"]= categories.First();
}
I have tried to populate a dropdown list box in kendo grid with the example given in kendo demos “Editing Custom editor”. But its not
working , it shows error in the view itself in the following set of line
model.Field(p =>p.Customer).DefaultValue(ViewData["defaultCategory"] as FOO.Models.ResourceModel);
and the error is
Cannot Convert from FOO.Models.ResourceModel to string
Can anyone help me out what is the mistake in the code ?
Mayil.M
On Behalf of
Jeremy Thompson