atrljoe
atrljoe

Reputation: 8151

FormView Checkbox Binding Problem

I am using a FormView to display data from a SQL database, when I try to bind a checkbox to a field in the database that contains only true or false in the value (NONE OF THE VALUES ARE NULL). I get the error "Specified cast is not valid" Ive tried Eval and Bind and neither work both produce the same error anyone know what the problem might be?

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

The values that are in every row is exactly "true" or "false" no 1 or 0 or "T" of "F". They are stored in a varchar column in the database.

Upvotes: 0

Views: 1795

Answers (2)

jth_92
jth_92

Reputation: 1160

You can use Eval in this manner:

<asp:CheckBox ID="IVT" runat="server" 
            Checked='<%# Eval("ContactInvite").ToString() == "True" %>' />

Upvotes: 1

SecretDeveloper
SecretDeveloper

Reputation: 3140

Does the ContactInvite column only contain TRUE/FALSE values as strings? If they are 0/1 or T/F then setting the property wont work. Can you provide us with the values that the ContactInvite field contains?

Upvotes: 0

Related Questions