I have a ASP.NET GridView
with a column mapped to a boolean. I want do display \"Yes\"/\"No\" instead of \"True\"/\"False\". Well actually I want \"Ja\"/\"Nej\"
Add a method to your page class like this:
public string YesNo(bool active)
{
return active ? "Yes" : "No";
}
And then in your TemplateField
you Bind
using this method:
<%# YesNo(Active) %>
I had the same need as the original poster, except that my client's db schema is a nullable bit (ie, allows for True/False/NULL). Here's some code I wrote to both display Yes/No and handle potential nulls.
Code-Behind:
public string ConvertNullableBoolToYesNo(object pBool)
{
if (pBool != null)
{
return (bool)pBool ? "Yes" : "No";
}
else
{
return "No";
}
}
Front-End:
<%# ConvertNullableBoolToYesNo(Eval("YOUR_FIELD"))%>
It's easy with Format()-Function
Format(aBoolean, "YES/NO")
Please find details here: https://msdn.microsoft.com/en-us/library/aa241719(v=vs.60).aspx