error message "String was not recognized as a valid Boolean" in aspx page

Csharp picture Csharp · Nov 14, 2013 · Viewed 9k times · Source

I have a SQL stored proc where I am creating a column ("Certified") dynamically based on two other columns. The value from this column is a '0' or '1'. The SQL stored proc query is:

, CASE WHEN 
    (StartMiles < EndMiles) 
    AND (StartTime < EndTime) 
    AND (bcd.Status != 'C')
     THEN '1' ELSE '0' END
     AS Certified

On the front end in my aspx page, I have a telerik radgrid that will display a checkbox (enabled if value is 1, disabled if value is 0). The aspx code is:

<telerik:GridTemplateColumn DataField="Certified" HeaderText="Certified" Visible="true">
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" 
        OnCheckedChanged="CheckBox2_CheckedChanged" 
        Enabled='<%# !bool.Parse(Eval("Certified").ToString()) %>' />
    </ItemTemplate>
</telerik:GridTemplateColumn>  

I am getting an error on the aspx page String was not recognized as a valid Boolean
To resolve the error, how can I set a datatype in the stored proc?

Answer

Andrew Paes picture Andrew Paes · Nov 14, 2013
<telerik:GridTemplateColumn DataField="Certified" HeaderText="Certified" Visible="true">
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" 
            OnCheckedChanged="CheckBox2_CheckedChanged" 
            Enabled='<%# !Convert.ToBoolean(Convert.ToInt32(Eval("Certified").ToString())) %>' />
    </ItemTemplate>
</telerik:GridTemplateColumn>