Displaying "Yes" instead of "True"

Posts   
 
    
JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 30-Dec-2004 22:26:38   

I have a typed list I bind to a .NET grid, and one of the fields is a bit field. Grid displays "True" and "False" when I want "Yes" and "No". Anybody got a quick fix?

cmartinbot
User
Posts: 147
Joined: 08-Jan-2004
# Posted on: 30-Dec-2004 22:54:04   

txtBox.Text = (myObject.BitField) ? "Yes" : "No";

That's a common "shortcut" for saying

if(myObject.BitField == true) { txtBox.Text = "Yes"; } else { txtBox.Text = "No"; }

Of course that is C# code. If you're using VB.NET I think you'll have to settle on the if statement. But, I have never even touched that language. smile

JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 31-Dec-2004 04:04:24   

Thanks, I know the shortcut because I'm an old C++ hand. I'm binding to a grid, though, not a textbox. But I found the solution, and you'll be pleased I was able to keep in inline using the same syntax.

I replaced this

 <asp:BoundColumn DataField="Active" SortExpression="Active" HeaderText="Active"></asp:BoundColumn>

with this

 <asp:TemplateColumn SortExpression="Active" HeaderText="Active">
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# ((bool)DataBinder.Eval(Container, "DataItem.Active")) ? "Yes" : "No" %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateColumn>

(grid is read-only or <EditTemplate> would be necessary too)

simple_smile