[英]MVC Telerik Grid Format column bool to string
是否可以將布爾值格式化為Telerik網格中的字符串?
我需要將布爾值(true / false)更改為字符串(是/否)。
我的模特:
[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'#");
在我的示例中,我檢查了兩件事,即價格是否大於零,以及是否需要,因為我有三個選擇。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.