Search code examples
c#asp.netasp.net-mvc-2teleriktelerik-grid

MVC Telerik Grid Format column bool to string


Is it possible to format a Boolean to string in a Telerik Grid?

I need to change the value of a Boolean (true/false) to string (Yes/No).

My model:

[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; }

My View:

<%= 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"))

%>

In columna.Bound(d => d.SeVePandora).Format() lambda expresions are not allowed.

Can someone help me?


Solution

  • I modified your code @jayesh-goyani. Telerik Grid needs a '<' to open logic in

    .ClientTemplate

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

    Thank you for your help!