Link to home
Start Free TrialLog in
Avatar of newjeep19
newjeep19Flag for United States of America

asked on

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=""--%>
                                                        </ItemTemplate>

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
Avatar of newjeep19
newjeep19
Flag of United States of America image

ASKER

The error message that I get is : String was not recognized as a valid Boolean
Avatar of Fernando Soto
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.
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?
Example of leading and trailing spaces would be "   true    ", "True   " or "   true".
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")  %>'/>
Can you remove the comment out of the <ItemTemplate> tag in the line of code and try it again.
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'
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.