Roland Schaer
Roland Schaer

Reputation: 1668

How do I convert a boolean from true/false to yes/no on a Telerik ASP .NET MVC Grid

I would like to be able to change the display value of a non-editable column on a non-editable Telerik AJAX grid in ASP.NET MVC. The column in question is a boolean value sot the display conversion would be Yes=true and No-False.

Upvotes: 6

Views: 7755

Answers (4)

user2486488
user2486488

Reputation: 111

I struggled with this for a while - In my case the < > around the expression in the ClientTemplate didn't seem to work. I spotted the problem by viewing the generated html - it was generating tags such as <no></no>. The following works fine for me:

          columns.Bound(c => c.DHSLane).Title("DHS Lane")
                 .ClientTemplate("#=DHSLane?'Yes':'No'#")

Upvotes: 0

Roland Schaer
Roland Schaer

Reputation: 1668

I did a little experimenting and found this works. Not sure if it will hold up on an editable column but in my case the column is not editable.

<% Html.Telerik().Grid<SomeClass>()
   .Name("SomeGrid")
   .Columns(columns =>
   {
      columns.Bound(o => o.ReportingPeriodShortDescription);
      columns.Bound(o => o.Closed)
          .ClientTemplate("<#=Closed ? 'Yes' : 'No' #>")
          .Title("Closed")
          .Width("4em");
   })
   .Footer(false)
   .Render();
%>

Upvotes: 6

Harbinger
Harbinger

Reputation: 604

I found an example on Telerik forums that walkthrough doing it based on server or client bindings.

http://www.telerik.com/community/forums/aspnet-mvc/grid/changing-a-bool-field-to-display-yes-no.aspx

In my case I'm using AJAX binding so I need a ClientTemplate:

columns.Bound(model => model.SubLimits).Title("Sublimits").Width(100)
    .ClientTemplate("<#=SubLimits?'Yes':'No'#>");

Upvotes: 0

IAmTimCorey
IAmTimCorey

Reputation: 16757

Use a template to convert the value from True/False to Yes/No. Here is an example of how to do so:

http://www.telerik.com/community/forums/aspnet-ajax/grid/how-do-i-show-yes-no-for-boolean-columns-instead-of-true-false.aspx

Upvotes: 0

Related Questions