C# MVC Telerik网格格式列布尔到字符串

C# MVC Telerik网格格式列布尔到字符串,c#,asp.net,asp.net-mvc-2,telerik,telerik-grid,C#,Asp.net,Asp.net Mvc 2,Telerik,Telerik Grid,是否可以将布尔值格式化为Telerik网格中的字符串 我需要将布尔值(真/假)更改为字符串(是/否) 我的模型: [DataMember] [DisplayName("PANDORA")] public bool SeVePandora { get; set; } [DataMember] [DisplayName("PORTOS")] public bool SeVePortos { get; set; } [DataMember] [DisplayName("CARRIER")] publi

是否可以将布尔值格式化为Telerik网格中的字符串

我需要将布尔值(真/假)更改为字符串(是/否)

我的模型:

[DataMember]
[DisplayName("PANDORA")]
public bool SeVePandora { get; set; }
[DataMember]
[DisplayName("PORTOS")]
public bool SeVePortos { get; set; }
[DataMember]
[DisplayName("CARRIER")]
public bool SeVeCarrier { get; set; }
[DataMember]
[DisplayName("CALCULADORA")]
public bool SeVeCalculadora { get; set; }
[DataMember]
[DisplayName("CONTROL STOCK")]
public bool SeVeControlStock { get; set; }
[DataMember]
[DisplayName("REMARKETING")]
public bool SeVeRemarketing { get; set; }
[DataMember]
[DisplayName("AUTO CREDIT")]
public bool SeVeAutocredit { get; set; }
[DataMember]
[DisplayName("VALORES RESIDUALES")]
public bool SeVeValoresResiduales { get; set; }
[DataMember]
[DisplayName("PRUEBAS")]
public bool EntornoPruebas { get; set; }
我的看法是:

<%= Html.Telerik().Grid<VWIS.DataModels.Models.AvisosPromociones.Avisos>()
.Name("ListAvisos")
.Columns(columna =>
    {
        columna.Bound(d => d.IdAViso).Visible(false).Sortable(false);
        columna.Bound(d => d.Titulo).Width(380).Sortable(false);
        columna.Bound(d => d.FechaInicio).Format("{0:dd/MM/yyyy}").Width(95).Sortable(true);
        columna.Bound(d => d.FechaFin).Format("{0:dd/MM/yyyy}").Width(86).Sortable(true);
        columna.Bound(d => d.SeVePandora).Width(50).Sortable(false);
        columna.Bound(d => d.SeVePortos).Width(50).Sortable(false);
        columna.Bound(d => d.EntornoPruebas).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeCarrier).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeCalculadora).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeControlStock).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeRemarketing).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeAutocredit).Width(50).Sortable(false);
        columna.Bound(d => d.SeVeValoresResiduales).Width(50).Sortable(false);
        }).DataBinding(datos => datos.Ajax().Select("_BusquedaAvisos", "Avisos", new { PrimeraBusqueda = true }))
                   .Pageable(page => page.PageSize(10))
                   .Selectable()
                   .Sortable()
                   .Reorderable(reorder => reorder.Columns(true))
                   .ClientEvents(e => e.OnDataBinding("OnDataBinding").OnRowSelect("SeleccionarFila"))

%>

{
columna.Bound(d=>d.IdAViso).Visible(false).Sortable(false);
columna.Bound(d=>d.Titulo).Width(380).Sortable(false);
columna.Bound(d=>d.FechaInicio).Format(“{0:dd/MM/yyyy}”).Width(95).可排序(true);
columna.Bound(d=>d.FechaFin).Format(“{0:dd/MM/yyyy}”).Width(86).可排序(true);
columna.Bound(d=>d.SeVePandora).Width(50).Sortable(false);
columna.Bound(d=>d.severtos).Width(50).Sortable(false);
columna.Bound(d=>d.EntornoPruebas).Width(50).Sortable(false);
columna.Bound(d=>d.SeVeCarrier).Width(50).Sortable(false);
columna.Bound(d=>d.SeVeCalculadora).Width(50).Sortable(false);
columna.Bound(d=>d.SeVeControlStock).Width(50).Sortable(false);
columna.Bound(d=>d.severemarking).Width(50).Sortable(false);
columna.Bound(d=>d.SeVeAutocredit).Width(50).Sortable(false);
columna.Bound(d=>d.SeVeValoresResiduales).Width(50).Sortable(false);
}).DataBinding(datos=>datos.Ajax()
.Pageable(page=>page.PageSize(10))
.可选()
.Sortable()
.Reorderable(reorder=>reorder.Columns(true))
.ClientEvents(e=>e.OnDataBinding(“OnDataBinding”).OnRowSelect(“seleccianfila”))
%>
columna.Bound(d=>d.SeVePandora).Format()中,不允许lambda表达式


有人能帮我吗?

请尝试下面的代码片段

colums.Bound(d => d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
    "# if (SeVePandora == true) { #" +
        "<span>Yes</span>" +
    "# } else { #" +
        "<span>No</span>" +
    "# } #"
);
colums.Bound(d=>d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
“#如果(SeVePandora==true){#”+
“是的”+
“}否则{”+
“没有”+
"# } #"
);

有关详细信息,请链接。

请使用下面的代码片段进行尝试

colums.Bound(d => d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
    "# if (SeVePandora == true) { #" +
        "<span>Yes</span>" +
    "# } else { #" +
        "<span>No</span>" +
    "# } #"
);
colums.Bound(d=>d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
“#如果(SeVePandora==true){#”+
“是的”+
“}否则{”+
“没有”+
"# } #"
);

有关更多信息,请链接。

我修改了您的代码@jayesh goyani。Telerik网格需要一个“我修改了你的代码@jayesh goyani。Telerik网格需要一个“,只有客户端模板可以像下面那样更简单

columns.Bound(c => c.Required).Width(65)
    .ClientTemplate("#= Price > 0 ? Required ? 'Yes' : 'No' : 'N/A'#");

在我的示例中,如果价格大于零,我会检查两件事,如果需要,我会检查两件事,因为我有三个选项

只有客户端模板可以更简单,如下所示

columns.Bound(c => c.Required).Width(65)
    .ClientTemplate("#= Price > 0 ? Required ? 'Yes' : 'No' : 'N/A'#");

在我的示例中,如果价格大于零,我会检查两件事,如果需要,我会检查两件事,因为我有三个选项

这个代码不起作用。我有Telerik组件和常见问题解答是为KendoI将提供工作演示稍后。您的要求在bool字段中您想显示是/否?是,
bool
字段必须是字符串yes/no。此代码无效。我有Telerik组件和常见问题解答是为KendoI将提供工作演示稍后。您的要求在bool字段中是否要显示是/否?是,
bool
字段必须是字符串是/否。我有相同的问题,并且我的代码与您的代码一样不起作用:columns.Bound(cb=>cb.Status).Width(60).ClientTemplate(“+”Active“+”)+不活动“+”);我得到一个JavaScript错误,该错误表示“Status is not defined.”如果我删除客户端模板,布尔字段将正确呈现,尽管呈现的是true/false。我也有同样的问题,我的代码与你的代码一样无法工作:columns.Bound(cb=>cb.Status).Width(60).ClientTemplate(“+”Active”+“”+“非活动”+“”);我得到一个JavaScript错误,该错误表示“Status is not defined”。如果我删除客户端模板,布尔字段将正确呈现,尽管呈现为true/false。