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

Dropdown List shows error in Kendo Grid incell editing - MVC

1 Answer 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 21 Oct 2013, 03:42 PM
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

 

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 23 Oct 2013, 03:50 PM
Hello Jeremy,

It looks like you are not passing appropriate value to the DefaultValue method. Did you try to add ToString() to your value? 

If still struggling create a sample project which we can run and investigate on our side.


Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or