tags:

views:

15

answers:

1

I need to create and html helper extention which takes boolean and returns string depending on the boolean value

    public static string ConvertToString(this HtmlHelper helper, bool val)
    {
        if (val)
        {
            return "Y";
        }

        return "N";
    }

The problem is how can I intergrate this to the below telerik grid column. I want to make the o.MultipleCurrencyFlag which is a boolean should give me Y or N

       <% Html.Telerik().Grid(Model)
        .Name("grid").Footer(false).Columns(columns =>
        {
                columns.Bound(o => o.MultipleCurrencyFlag).HtmlAttributes(new {@class = "currency"}).Title(Html.Resource("MultipleCurrencyTableHeader"));
        }
        ).Pageable(pager => pager.PageSize(25))
        .Footer(true)
        .Render(); 

         %>

Below code need to change it to use the Html.ConvertToString(o.MultipleCurrencyFlag)

          columns.Bound(o => o.MultipleCurrencyFlag).HtmlAttributes(new {@class = "currency"}).Title(Html.Resource("MultipleCurrencyTableHeader"));

//edit I also tried columns.Bound(o => o.MultipleCurrencyFlag).Format(Html.ConvertToString(o => o.MultipleCurrencyFlag)).HtmlAttributes(new { @class = "currency" }).Title(Html.Resource("MultipleCurrencyTableHeader"));

I cannot get this to work. Please help

A: 

Assuming you are using server binding, this will do it for you:

columns.Template(o=> { %>
                           <%=Html.ConvertToString(o.MultipleCurrencyFlag)%>
                  <% })
       .HtmlAttributes(new { @class = "currency"})
       .Title(Html.Resource("MultipleCurrencyTableHeader"));

-Josh

Joshua