1

我有一个网格,其中一列有一个带有下拉列表的 EditorTemplate。

columns.Bound(i => i.TypeId).Title("Types").EditorTemplateName("Types").ClientTemplate("#: TypeId != 3 ? Type : '-'#").HtmlAttributes(new { @style = "text-align:center; " }).Width(75);

模板

@(Html.Kendo().DropDownListFor(i => i)
                .Name("TypeId")
                .DataValueField("Id")
                .DataTextField("Type")
                .BindTo((IEnumerable)ViewBag.Types)
                .OptionLabel("Select Type")
                .Value("TypeId")
)

我想要实现的是当 TypeId 为 3 时我不想使用编辑器模板。我只想显示禁用状态的“-”。

我可以使用 onedit 事件禁用下拉列表,但我不希望下拉列表即使在禁用状态下也显示。

任何想法将不胜感激。

我做了什么来禁用模板,如下所示:

 function disableOnEdit(e) {

        if (e.model.isNew()) {
            // Leave it editable if the row is new.
        } else {
             //Disable the editor for Element in this row.
            var select = e.container.find('input[name=TypeId]').data('kendoDropDownList');
            if (select != null && select._selectedValue == "3") {
                //var text = select.find(".k - input");
                //select.dataSource = null;
                //select._selectedValue = "-";
                //select.editTemplate = null;
                //select.innerHTML = "-";
                //select._current[0].innerText = "-";
                select.enable(false);
            } 
        }
    }

我已经尝试了很多方法来从列中删除下拉列表。我是 Kendo UI 的新手,所以请帮助我。

谢谢

4

1 回答 1

0

您可以更改您的模板,如下所示

@model Int32

@if(Model !=3){
@(Html.Kendo().DropDownListFor(i => i)
            .Name("TypeId")
            .DataValueField("Id")
            .DataTextField("Type")
            .BindTo((IEnumerable)ViewBag.Types)
            .OptionLabel("Select Type")
            .Value("TypeId"))
}else{
    @Html.TextBox("",Model,new{disabled="disabled"})
}
于 2014-09-13T08:05:18.930 回答