Change selected value of kendo ui dropdownlist

后端 未结 5 1004
忘掉有多难
忘掉有多难 2020-12-28 13:18

I have a kendo ui dropdownlist in my view:

$(\"#Instrument\").kendoDropDownList({
    dataTextField: \"symbol\",
    dataValueField: \"symbol\",
    dataSour         


        
5条回答
  •  盖世英雄少女心
    2020-12-28 13:36

    Since this is one of the top search results for questions related to this I felt it was worth mentioning how you can make this work with Kendo().DropDownListFor() as well.

    Everything is the same as with OnaBai's post except for how you select the item based off of its text and your selector.

    To do that you would swap out dataItem.symbol for dataItem.[DataTextFieldName]. Whatever model field you used for .DataTextField() is what you will be comparing against.

    @(Html.Kendo().DropDownListFor(model => model.Status.StatusId)
        .Name("Status.StatusId")
        .DataTextField("StatusName")
        .DataValueField("StatusId")
        .BindTo(...)
    )
    
    //So that your ViewModel gets bound properly on the post, naming is a bit 
    //different and as such you need to replace the periods with underscores
    var ddl = $('#Status_StatusId').data('kendoDropDownList');    
    
    ddl.select(function(dataItem) {
        return dataItem.StatusName === "Active";
    });
    

提交回复
热议问题