Click here to Skip to main content
14,869,895 members
Please Sign up or sign in to vote.
4.29/5 (3 votes)
See more:
In Database value datatype is String.I entered values in database like "Y" or "N". If i want to bind that value into checkbox in gridview using am using this code
                <asp:CheckBox ID="chkReimbursable" runat="server"
       Text ='<%# (Convert.ToBoolean(Eval("[GroupFlag]"))) %>'/>

But i am gettting "String was not recognized as a valid Boolean" this issue

Please resolve this issue
Updated 3-Sep-13 18:45pm
kishore sharma 4-Sep-13 1:57am
how can you convert Y to boolean

1 solution

in text property u can not provide Boolean value.

try this to checked property
<asp:CheckBox ID="chkReimbursable" runat="server"
 Text="your text"    Checked ='<%# (Convert.ToBoolean(Eval("[GroupFlag]"))) %>'/>

your groupflag value must be 'true' or '1'
krish2013 3-Sep-13 7:55am
I tried that code but i am getting same my database my value 'T'and 'N'
[no name] 3-Sep-13 8:37am
dont use 'T' and 'N' use '1' and '0 or 'true' and 'false'' in database as value
Harshil_Raval 3-Sep-13 8:08am
Hi, as you said your database have value 'T' and 'N'. Then in your sp or query, you must check for this values, if 'Y' then convert to 1 and if 'N' then convert to 0. It may solve your issue.
krish2013 4-Sep-13 0:28am
I used string datatype in database is it corrrect or not
Harshil_Raval 4-Sep-13 1:19am
No, for this you should use boolean value. change your db field from string to bit
[no name] 4-Sep-13 3:44am
if u use proper conversion then it not matter but u should take as Boolean in database for future aspects

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900