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

Display dropdownlist in Grid with inline batch editing

2 Answers 317 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Avinash
Top achievements
Rank 1
Avinash asked on 19 Jan 2016, 05:46 PM

I am trying to follow this example http://demos.telerik.com/aspnet-mvc/grid/editing-custom to display dropdown when user clicks on grid cell. However everytime when i view the grid, it only shows text 'undefined' instead of the actual dropdownlist.

Here is what i did:

ViewModel:

public class CommonDetailsViewModel
{
    public List<UOMItem> UOMs  { get; set; }
}
 
public class UOMItem
{
    public string UserDefinedCode {get; set;}
}

 Controller:

CommonDetailsViewModel commonDetailsViewModel = commonService.InvokeGetCommonDetails(flag);
var uomList = new SelectList(commonDetailsViewModel.UOMs, "UserDefinedCode", "UserDefinedCode");
ViewData["UOMList"] = uomList;

ClientTemplates: Added UOM.cshtml inside 'Views/Shared/ClientTemplates' folder

@using System.Collections
@using Kendo.Mvc.UI;
 
@(Html.Kendo().DropDownList()
.BindTo((IEnumerable)ViewData["UOMList"])
    .OptionLabel("- Select UOM - ")
    .DataValueField("UserDefinedCode")
    .DataTextField("UserDefinedCode")
)

 View:

@(Html.Kendo().Grid<SupplierPortal.ViewModels.CreateAsnRequestViewModel>()
      .Name("GridViewOpenPOSelected")
      .Columns(columns =>
      {
        columns.Bound(p => p.UPCUOM).HtmlAttributes(new { @class = "editableFiled" }).ClientTemplate("#=UOM.UserDefinedCode#").Width(180);                         
      })
    .Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
    .AutoBind(false)
    .Navigatable()
    .DataSource(dataSource => dataSource
                .Ajax()
                .Batch(true)
                .PageSize(10)
                .Read(read => read.Action("GetSelectedPO", "Asn").Data("GetSelectedPOParameters"))
                .ServerOperation(false)
                .Model(model =>
                {
                    model.Id(p => p.Id);
                    model.Field(p => p.UPCUOM).DefaultValue("EA");
                }))
    .Events(events => events.DataBound("gridDataBound"))
    .Events(events => events.DataBinding("gridDataBinding"))
    .Events(events => events.Edit("onEdit"))
)                                                                                                                                        

 

Now everytime when i view the grid, the UPCUOM cell shows 'undefined'.

Any clue what am i doing wrong?

Thanks.

 

2 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 21 Jan 2016, 09:03 AM

Hello Avinash,

 

Could you please provide the CreateAsnRequestViewModel class definition? I noticed that the Kendo UI Grid for ASP.NET MVC is populated with CreateAsnRequestViewModel data. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Avinash
Top achievements
Rank 1
answered on 21 Jan 2016, 04:35 PM

Boyan,

Apology but instead of replying in this post i ended up creating new post related to this issue. You can delete this post and follow on this issue instead:

http://www.telerik.com/forums/dropdownlist-reverts-back-to-'null'-value-after-selection-is-moved-in-the-grid-asp-mvc-5

Note: You can find CreateASNRequestViewModel in that post. 

 Thanks.

Tags
Grid
Asked by
Avinash
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Avinash
Top achievements
Rank 1
Share this question
or