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

若如初见. 提交于 2019-12-08 22:07:01

问题


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.


回答1:


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();
%>



回答2:


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




回答3:


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'#>");



回答4:


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'#")


来源:https://stackoverflow.com/questions/5966916/how-do-i-convert-a-boolean-from-true-false-to-yes-no-on-a-telerik-asp-net-mvc-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!