网格背景下降和文本不同的颜色

时间:2014-12-15 14:27:15

标签: kendo-ui telerik kendo-grid

我尝试使用column.beound在telerik mvc网格中添加下拉列表我可以显示下拉列表,但最初它显示为文本框。显然,如果我使用编辑器模板它应该工作,但我得到的错误值不能为空?

目的是在网格中显示下拉列表,每个项目将具有不同的文本颜色和背景。这需要通过模型属性填充。

目前我使用ViewData只是为了让事情顺利进行,但没有快乐。被告知这可以通过模板完成。

为什么这不起作用的任何想法?

@using System.Collections.Generic;
@model IEnumerable<TelerikChecklist.Models.ProductViewModel>


@(Html.Kendo().Grid(Model)
.Name("gridDropDown")
.Columns(columns =>
{
    columns.Bound(p => p.ProductName);
    //columns.ForeignKey(p => p.CategoryID,     (System.Collections.IEnumerable)ViewData["categories"], "CategoryID", "CategoryName")
    //  .Title("Category")
    //  .Width(150);

    columns.Bound(p => p.CategoryID).Title("Category Name").ClientTemplate((@Html.Kendo().DropDownList()
        .Name("dropdown_#=CategoryID#")
        .BindTo((System.Collections.IEnumerable)ViewData["categories"])
        .DataTextField("CategoryName")
        .DataValueField("CategoryID")
        .ValueTemplate("")
        .ToClientTemplate().ToString()
        )).EditorTemplateName("GridForeignKey");

})
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:250px;" })

    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .PageSize(20)
        .ServerOperation(false)
        .Events(events => events.Error("errorHandler"))
        .Model(model =>
        {
            model.Id(p => p.ProductID);
            model.Field(p => p.ProductID).Editable(false);
            model.Field(p => p.CategoryID).DefaultValue(1);
        })

        .Read(read => read.Action("ForeignKeyColumn_Read", "Home"))
        .Update(update => update.Action("ForeignKeyColumn_Update", "Home")).Events(e => e.Change("Category"))
        .Create(create => create.Action("ForeignKeyColumn_Create", "Home"))
        .Destroy(destroy => destroy.Action("ForeignKeyColumn_Destroy", "Home"))



    )

GridForeignKey.cshtml

@model object

@(
Html.Kendo().DropDownListFor(m => m)        
    .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])

)

1 个答案:

答案 0 :(得分:0)

通过创建另一个模板解决:

columns.Bound(p => p.Category.CategoryName).Title("CategoryName").EditorTemplateName("GridForeignKey2");

@using System.Collections;

@(Html.Kendo().DropDownList()
        .Name("NeatProperty")
        .DataTextField("CategoryName")
        .DataValueField("CategoryID")
        .BindTo((System.Collections.IEnumerable)ViewData["categories"])
        .Template("<div style='background-color:#: data.CategoryColor #'><span class=\"k-state-default\"></span>" + "<span class=\"k-state-default\"><p style='color:#: data.CategoryTextColor #;'>#: data.CategoryName #</p></span></div>")
        .ValueTemplate("<div style='background-color:#: data.CategoryColor #;'><span>#:data.CategoryName#</span></div>")

在stackoverflow上的另一篇文章中看到这个,但丢失了链接,因此无法发布。

相关问题