T
TJ
I have a datagrid that has a boolean column. The sql data is a bit stored
as a 1 or 0. Doing a straight up DataBinder.Eval(Container.DataItem,
"MyColumn") displays a "True" or "False" in the grid. No problems here.
What I want is for it to display a "Yes" or "No". So I'm using a
TemplateColumn instead of a BoundColumn so I can pass the value into a
function and return a string that says Yes or No. My problem is that the
function won't take the value seemingly no matter how I cast or don't cast
the argument when I send or in the receiving mechanism of the function.
In the aspx page:
<asp:TemplateColumn HeaderText="Approved">
<ItemTemplate>
<%# FormatYesOrNo(DataBinder.Eval(Container.DataItem, "MyBitColumn")) %>
</ItemTemplate>
</asp:TemplateColumn>
In the code behind:
public string FormatYesOrNo(bool x)
{
string z = "Yes";
if (x != true)
z = "No";
return z;
}
I tried casting the late bound info the aspx to a bool (e.g.
(bool)DataBinder.Eval...), but that didn't work. I tried changing the
FormatYesOrNo(bool x) in the code behind to FormatYesOrNo(string x) and
changing the guts accordingly, but that didn't work.
Any help appreciated.
-TJ
as a 1 or 0. Doing a straight up DataBinder.Eval(Container.DataItem,
"MyColumn") displays a "True" or "False" in the grid. No problems here.
What I want is for it to display a "Yes" or "No". So I'm using a
TemplateColumn instead of a BoundColumn so I can pass the value into a
function and return a string that says Yes or No. My problem is that the
function won't take the value seemingly no matter how I cast or don't cast
the argument when I send or in the receiving mechanism of the function.
In the aspx page:
<asp:TemplateColumn HeaderText="Approved">
<ItemTemplate>
<%# FormatYesOrNo(DataBinder.Eval(Container.DataItem, "MyBitColumn")) %>
</ItemTemplate>
</asp:TemplateColumn>
In the code behind:
public string FormatYesOrNo(bool x)
{
string z = "Yes";
if (x != true)
z = "No";
return z;
}
I tried casting the late bound info the aspx to a bool (e.g.
(bool)DataBinder.Eval...), but that didn't work. I tried changing the
FormatYesOrNo(bool x) in the code behind to FormatYesOrNo(string x) and
changing the guts accordingly, but that didn't work.
Any help appreciated.
-TJ