【问题标题】:dropdown in grid background and text different color网格背景中的下拉菜单和不同颜色的文本
【发布时间】:2014-12-15 14:27:14
【问题描述】:

我正在尝试使用 column.Bound 在 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"])

)

【问题讨论】:

标签: kendo-ui telerik kendo-grid


【解决方案1】:

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

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

@使用 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上的另一篇帖子中看到了这个,但链接丢失了,所以无法发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    相关资源
    最近更新 更多