dropdownlist in kendo ui grid not selecting any va

2019-06-09 07:30发布

问题:

Currently i have inline editing grid as in the following, I have drop down list in coloumn CStatusID, However, it does not selected value into when trying to save to database

VIEW:

@(Html.Kendo().Grid(Model)
    .Name("SList")
        .HtmlAttributes(new { @Style = "align:center; font-size:10px;" })
    .Columns(columns => {
        columns.Bound(p => p.CCID);
        columns.Bound(p => p.CRN);
        columns.Bound(p => p.CStatusID).EditorTemplateName("CStatus
");
        columns.Bound(p => p.DateScheduled).Format("{0:MM/dd/yyyy}");

        columns.Command(commands => commands.Edit()).Width(175);
    })
    //.ToolBar(toolBar => toolBar.Save())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable()
    .Navigatable()
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Single)
                                        .Type(GridSelectionType.Row))
    .DataSource(dataSource => dataSource        
        .Ajax()
        .PageSize(10)   
        .Model(model => model.Id(p => p.ConsumerID))
        .Read(read => read.Action("Index", "Management"))
        .Update(update => update.Action("Edit", "Management"))

    )
)

and I have CStatus.cshtml under shared/Editor template:

@(Html.Kendo().ComboBox()
        .Name("Status")
        //.OptionLabel("Select status")
        .DataValueField("OptID")
        .DataTextField("OptName")
        .BindTo((System.Collections.IEnumerable)ViewData["constStatus"])


)

Controller:

public ActionResult Index()
        {
            PopulateConstStatus();
            return View();
        }

private void PopulateConstStatus()
        {
            ViewData["constStatus"] = new EDEntities().COptions
                       .Select(e => new ConfOptModel
                       {
                           OptionID = e.OptID,
                           OptionName = e.OptName,
                           CTypeID = e.CTypeID
                       })
                       .Where(e => e.CTypeID == 2)
                       .OrderBy(e => e.OptName);
        }

Model

public int OptID { get; set; }
public string OptName { get; set; }

[UIHint("CStatus")]
public COptionsModel COptionsModel { get; set; }

回答1:

I follow this and it work as a charm

http://demos.kendoui.com/web/grid/foreignkeycolumn.html



回答2:

Try adding the following event in the kendo grid

.Events(events =>
{
    events.Save("TestPointGrid_Save");
})

and the following script

<script type="text/javascript">
    function TestPointGrid_Save(e) {
        var companyId = $("#NameoftheDropdownlist").data().kendoDropDownList.value();
        e.model.set("NameoftheDropdownlist", companyId);
    }
</script>

you can refer this link for more information