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.
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();
%>
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
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'#>");
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'#")
精彩评论