When I try to add a new row to an ASP. NET gridview table I get this error message. String was not recognized as a valid Boolean

I have a gridview table that has a row when retruned shows a textbox checked or not. When I try to add a new row to that gridview table is when I get the error message.

HERE is my ASP.NET Code
<ItemTemplate >   
                                                            <asp:CheckBox ID="chkAttended" runat="server" AutoPostBack="true" Checked='<%# Convert.ToBoolean(Eval("attended").ToString()) %>' /><%-- Checked='<%# Convert.ToBoolean(Eval("attended").ToString()) %>' Checked='<%# bool.Parse(Eval("attended").ToString()) %>' OnCheckedChanged=""--%>

Open in new window

I have been trying to figure out how to add a new row to the gridview table. The gridview is built from a stored proc and the column in the database table for "attended" is a nvarchar.
Please help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

newjeep19Author Commented:
The error message that I get is : String was not recognized as a valid Boolean
Fernando SotoRetiredCommented:
In order for the Convert.ToBoolean to return a boolean value it must be in the form of, "True", "true", "False", "false" or null which will return false. You can have space values in front or back of the string. All other values will return an exception. Check the values in the "attended" column and make sure it is in the correct format.
newjeep19Author Commented:
When I query the database the column for attended are either true (if they attended) or false (if they did not attend.
What would be an example of a space value in the string?
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Fernando SotoRetiredCommented:
Example of leading and trailing spaces would be "   true    ", "True   " or "   true".
newjeep19Author Commented:
When I added "true" and " false" to my sting they are either all checked or none are checked depending on the order in the string:

my code:
<asp:CheckBox ID="chkAttended" runat="server" Checked='<%# Convert.ToBoolean(Eval("attended").ToString() == "1" ? "false":"true")  %>'/>
Fernando SotoRetiredCommented:
Can you remove the comment out of the <ItemTemplate> tag in the line of code and try it again.
newjeep19Author Commented:
I can not then I get a "system.web.ui.webcontrols.templatefiled error basically telling me that I do not have a public property named 'CheckBox'
Fernando SotoRetiredCommented:
What happens when you do this.

<asp:CheckBox ID="chkAttended" runat="server" Checked='<%# Convert.ToBoolean(Eval("attended"))  %>'/>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Could you please write this line of code -

<asp:Label id="lblAttended" runat="server" Text='<%# Eval("attended").ToString() %>'/>

and share what you get for label text>

I would also like to have look for value by snapshot of same.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.