MVC Telerik Grid Format 列布尔值到字符串
本文关键字:布尔值 字符串 Format Telerik Grid MVC | 更新日期: 2023-09-27 17:56:29
是否可以在 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.SeVePandora).Format()
不允许使用lambda表达式。
有人可以帮助我吗?
请尝试使用以下代码片段。
colums.Bound(d => d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
"# if (SeVePandora == true) { #" +
"<span>Yes</span>" +
"# } else { #" +
"<span>No</span>" +
"# } #"
);
欲了解更多信息,请点击这里。
我@jayesh goyani修改了你的代码。Telerik Grid需要一个"<"来打开
中的逻辑 .ClientTemplate
`colums.Bound(d => d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
"<# if (SeVePandora == true) { #>" +
"<span>Yes</span>" +
"<# } else { #>" +
"<span>No</span>" +
"<# } #>"
);`
感谢您的帮助!
只有客户端模板可以像波纹管一样简单。
columns.Bound(c => c.Required).Width(65)
.ClientTemplate("#= Price > 0 ? Required ? 'Yes' : 'No' : 'N/A'#");
在我的示例中,如果价格大于零,如果需要,我会检查两件事,因为我有三个选择。