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

DropdownList in Grid Not preserving the previous value on Edit

2 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 12 Jun 2015, 01:34 PM

Hi All,

Struggling with a very peculiar problem.

I have a Kendo grid with kendo dropdownlist in some of the columns. The dropdown is populated based on values from in the database.

Problem:

On Edit in grid, the dropdown is not preserving previous saved value. 

Please can you help me in finding  the solution for the problem.

VIEW Code:

 @(Html.Kendo().Grid<ViaPath.LookUpDataManagement.MvcApp.Models.MasterDataMappingModel>(Model)
    .Name("gridTable")    
    .HtmlAttributes(new { style = "font-family: verdana,arial,sans-serif; font-size: 11px;color: #333333;border-color: #999999;" })
    .Columns(columns =>
    {
        columns.Bound(p => p.ClientAppName).ClientTemplate("# try {# #=ClientAppName# #} catch (e) {}#").EditorTemplateName("ClientComboBoxLookup").Width(120).Filterable(ft => ft.UI("ClientApplicationsFilter"));
      
        columns.Bound(p => p.SupplierAppName).ClientTemplate("# try {# #=SupplierAppName# #} catch (e) {}#").EditorTemplateName("SupplierComboBoxLookup").Width(120).Filterable(ft => ft.UI("SupplierApplicationsFilter"));
      
        columns.Bound(p => p.ListName).ClientTemplate("# try {# #=ListName# #} catch (e) {}#").EditorTemplateName("MasterDataListsComboBoxLookup").Width(150).Filterable(ft => ft.UI("ListsFilter"));
        columns.Bound(p => p.ClientValueName).Width(120).Title("Client Value");
        columns.Bound(p => p.ClientValueDescription).Width(200);
        columns.Bound(p => p.ClientCodingSystem).Width(150);
        columns.Bound(p => p.SupplierValueName).Width(120).Title("Supplier Value"); ;
        columns.Bound(p => p.SupplierValueDescription).Width(200);
        columns.Bound(p => p.SupplierCodingSystem).Width(150);
        columns.Bound(p => p.Direction).Width(90).ClientTemplate("# try {# #=Direction# #} catch (e) {}#").EditorTemplateName("DirectionComboBoxLookup").Filterable(ft => ft.UI("DirectionsFilter"));
        columns.Command(command =>  {
                command.Edit();
                command.Destroy();
            }).Width(200);
       
    })
            .ToolBar(t => t.Create())
            .Editable(editable => editable.Mode(GridEditMode.InLine))
            .Filterable(e => e.Extra(false))
            .Pageable(page => page.PageSizes(new int[] { 10, 25, 50, 100 }).Enabled(true))
            .Sortable()
            .Scrollable(src => src.Height("auto"))
            .Resizable(resize => resize.Columns(true))
            .DataSource(
                source => source
                    .Ajax() 
                    .Events(events => events.Error("error_handler"))                    
                    .ServerOperation(true)                  
                    .Model(model =>
                {
                    model.Id(e => e.MasterDataMappingId);
                    model.Field(e => e.MasterDataMappingId).Editable(false);
                    //model.Field(p => p.ClientAppName).Editable(true).DefaultValue(ViewData["defaultApplications"] as ViaPath.LookUpDataManagement.MvcApp.Models.MasterDataMappingModel);
                    //model.Field(p => p.SupplierAppName).Editable(true).DefaultValue(ViewData["defaultApplications"] as ViaPath.LookUpDataManagement.MvcApp.Models.MasterDataMappingModel);
                    //model.Field(p => p.ListName).Editable(true).DefaultValue(ViewData["defaultMasterDataList"] as ViaPath.LookUpDataManagement.MvcApp.Models.MasterDataMappingModel);
                    
                })                
                .Create(create => create.Action("Create_MasterDataMapping", "Home"))
                .Read(read => read.Action("Read_MasterDataMapping", "Home"))
                 .Update(update => update.Action("Update_MasterDataMapping", "Home"))
                 .Destroy(destroy => destroy.Action("Destroy_MasterDataMapping", "Home")))
                 //.Events(e => e.Edit("onEdit"))
            )

 Editor Template:

@(Html.Kendo().DropDownListFor(m => m)
        .Name("ClientAppName")
        .DataValueField("AppId")
        .DataTextField("ApplicationName")
        .BindTo((System.Collections.IEnumerable)ViewData["Applications"])
        .AutoBind(false)        
        .Events(e =>
        {
            e.Select("onSelect");
        })
)

2 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 15 Jun 2015, 12:22 PM

Hi All,

Need your help for the above post.

I am not sure where I am going wrong. Highly Appreciate any help.

Cheers

Dino

0
Daniel
Telerik team
answered on 16 Jun 2015, 12:25 PM
Hi,

I posted my reply in the support ticket on the same topic. For convenience, I am pasting it below. In order to avoid duplication lets continue either here or in the support thread.

At least from the field names(ClientAppName, ApplicationName) it seems that the bound field corresponds to the dropdonwlist text field and not to the value field which is required in order for correct item to be selected. If that is the case then you should bind the field from the grid model that corresponds to the AppId value in order to avoid the problem. You can still use a template to show the name e.g.
columns.Bound(p => p.ClientAppId).ClientTemplate("# try {# #=ClientAppName# #} catch (e) {}#")
@(Html.Kendo().DropDownListFor(m => m)
        .DataValueField("AppId")
        .DataTextField("ApplicationName")
        .BindTo((System.Collections.IEnumerable)ViewData["Applications"])
        .AutoBind(false)       
        .Events(e =>
        {
            e.Select("onSelect");
        })
)



Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or