Convert a Checkbox value to text in a Formview item template

G

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?
 
D

Dan Christensen

gadya said:
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.
 
G

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)%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top