I have a gridview with dynamic datasource.
I add column in codebehind .
BoundField col=new BundField();
col.DataField="Active";
col.DataFormatString=//DataFormatString;
gridview1.Columns.Add(col);
How do set yes/no for boolean column ?
I use this code for VB:
<asp:TemplateField HeaderText="Active" SortExpression="Active">
<ItemTemplate><%#IIf(Boolean.Parse(Eval("Active").ToString()), "Yes", "No")%></ItemTemplate>
</asp:TemplateField>
And this should work for C# (untested):
<asp:TemplateField HeaderText="Active" SortExpression="Active">
<ItemTemplate><%# (Boolean.Parse(Eval("Active").ToString())) ? "Yes" : "No" %></ItemTemplate>
</asp:TemplateField>
I have found that the solutions above using DataFormatString do not work for me in a GridView.
What worked for me was to use a template column, which I was trying to avoid...
I would have done that with SQL, when selecting data as:
select id, fname, (case when Active = 'true' then 'Yes' else 'No' end) AS Active from tblName
Now no need of formatting it anymore the returned column Active is replaced with another column with the same name but that contains the values of Yes/No.
I assumed your column active is a bit column that contains either true/false, but if something else replace the true/false with your values