2

I am using a .NET 3.5 ListView control and would like to display a TINYINT field value as a checkbox (0 = False, 1 = True).

How to do this?

I was trying:

<asp:CheckBox ID="freight_foundCheckbox" runat="server" 
Checked='<%# Eval("found") %>'  />

But this results in a Cast error.

3 Answers 3

3

Try this:

<asp:CheckBox ID="freight_foundCheckbox" runat="server" Checked='<%# Convert.ToBoolean(Eval("found")) %>'  />
Sign up to request clarification or add additional context in comments.

Comments

3

That won't work on an int field. You have to make sure the property you're binding to is a Boolean/bool.

Comments

1

The example above will throw an exception. You need to convert the value to bool:

<asp:CheckBox ID="freight_foundCheckbox" runat="server" Checked='<%# (int)Eval("found") == 1 ? true : false  %>' />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.