Home All Groups Group Topic Archive Search About

Convert a Checkbox value to text in a Formview item template

Author
9 Aug 2006 2:07 PM
gadya
In an Item template in a formview I have a checkbox thus:

parking:
<asp:CheckBox ID="parkingCheckBox" runat="server" Checked='<%#
eval("parking") %>'
Enabled="false" / >

However I don't want to display "parking" followed by a ticked/unticked box
but rather to display "parking" (in a label?) if the check box is ticked, and
not to display anything if it is unticked. How can I do this?

--
Victor

Author
9 Aug 2006 8:47 PM
Dan Christensen
gadya wrote:
> In an Item template in a formview I have a checkbox thus:
>
>  parking:
>  <asp:CheckBox ID="parkingCheckBox" runat="server" Checked='<%#
> eval("parking") %>'
>  Enabled="false" / >
>
> However I don't want to display "parking" followed by a ticked/unticked box
> but rather to display "parking" (in a label?) if the check box is ticked, and
> not to display anything if it is unticked. How can I do this?

Maybe setup something like (in C#):
....
<ItemTemplate>
<%# Eval("parking").ToString() == "1" : "parking" ? String.Empty %>
</ItemTemplate>
....

At least that's how I've done it with a DataGrid.
Author
10 Aug 2006 2:36 PM
gadya
Thanks a lot. I was surprised to find that the ternary operator did not exist
in vb.net and in VB the result looks like this:

  <%#IIf(Eval("parking") = "true", "parking </br>", String.Empty)%>

--
Victor


Show quoteHide quote
"Dan  Christensen" wrote:

> gadya wrote:
> > In an Item template in a formview I have a checkbox thus:
> >
> >  parking:
> >  <asp:CheckBox ID="parkingCheckBox" runat="server" Checked='<%#
> > eval("parking") %>'
> >  Enabled="false" / >
> >
> > However I don't want to display "parking" followed by a ticked/unticked box
> > but rather to display "parking" (in a label?) if the check box is ticked, and
> > not to display anything if it is unticked. How can I do this?
>
> Maybe setup something like (in C#):
> ....
> <ItemTemplate>
> <%# Eval("parking").ToString() == "1" : "parking" ? String.Empty %>
> </ItemTemplate>
> ....
>
> At least that's how I've done it with a DataGrid.
>
>