2014-04-04 34 views
1

是否有可能将布尔格式格式化为Telerik Grid中的字符串?MVC 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()拉姆达表达式还不允许的。

有人可以帮助我吗?

回答

2

我修改了你的代码@ jayesh-goyani。 Telerik的电网需要一个“<”在

.ClientTemplate

`colums.Bound(d => d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
    "<# if (SeVePandora == true) { #>" + 
     "<span>Yes</span>" + 
    "<# } else { #>" + 
     "<span>No</span>" + 
    "<# } #>" 
);` 

感谢你的帮助,以打开逻辑!

+0

我有同样的问题,我的代码,与你的一样,不起作用:columns.Bound(cb => cb.Status).Width(60).ClientTemplate( “<#if(Status == true){ #>” + “主动” + “<#}否则{#>” + “无效” + “<# } #>” );我收到一个JavaScript错误,指出“状态未定义”。如果我删除客户端模板,则布尔字段将正确呈现,尽管呈现的是真/假。 – SFAgitator

2

请试试下面的代码片段。

colums.Bound(d => d.SeVePandora).Width(50).Sortable(false).ClientTemplate(
    "# if (SeVePandora == true) { #" + 
     "<span>Yes</span>" + 
    "# } else { #" + 
     "<span>No</span>" + 
    "# } #" 
); 

欲了解更多信息请致电this链接。

+0

此代码无效。我有Telerik组件,常见问题解答是Kendo – Ark

+0

我将在稍后提供工作演示。你的要求是在你想显示yes/no的bool字段中? –

+0

是的,'bool'字段**必须**是一个字符串是/否。 – Ark