• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

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
0
newjeep19
Asked:
newjeep19
  • 4
  • 4
1 Solution
 
newjeep19Author Commented:
The error message that I get is : String was not recognized as a valid Boolean
0
 
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.
0
 
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?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Fernando SotoRetiredCommented:
Example of leading and trailing spaces would be "   true    ", "True   " or "   true".
0
 
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")  %>'/>
0
 
Fernando SotoRetiredCommented:
Can you remove the comment out of the <ItemTemplate> tag in the line of code and try it again.
0
 
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'
0
 
Fernando SotoRetiredCommented:
What happens when you do this.

<asp:CheckBox ID="chkAttended" runat="server" Checked='<%# Convert.ToBoolean(Eval("attended"))  %>'/>
0
 
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.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now