String was not recognized as a valid Boolean.

Hi Guys,

I am getting the error String was not recognized as a valid Boolean. Currently what I am trying to do is save the user's preference on a profile.

This will allow me to run a query against the database and match the results to that of the person's preferences on the profile? I have attached my Web.Config file, aspx and aspx.cs files. Please help!!!!!
Web Config File

 <customErrors mode="Off"></customErrors>
    <profile enabled="true" defaultProvider="AspNetSqlProfileProvider">
      <properties>
        <add name="SmokeP" type="boolean"/>
        <add name="GenderP" type="boolean"/>
        <add name="JourneyP" type="boolean"/>
      </properties>
    </profile>

ASPX File

<asp:Label ID="lblSmokeP" runat="server" Text="Select Smoking Preference" Font-Bold="true" Font-Size=8></asp:Label>
    <asp:RadioButtonList ID="rbSmokeP" runat="server" Font-size="8">
    <asp:ListItem>Smoker</asp:ListItem>
    <asp:ListItem>Non-Smoker</asp:ListItem>
    <asp:ListItem>Both</asp:ListItem>
    </asp:RadioButtonList>
    <br />
    <br />
    <asp:Label ID="lblGenderP" runat="server" Text="Select Gender Preference" Font-Bold="true" Font-Size=8></asp:Label>
    <asp:RadioButtonList ID="rbGenderP" runat="server" Font-size="8">
    <asp:ListItem>Male</asp:ListItem>
    <asp:ListItem>Female</asp:ListItem>
    <asp:ListItem>Both</asp:ListItem>
    </asp:RadioButtonList>
    <br />
    <br />
    <asp:Label ID="lblJourneyP" runat="server" Text="Select Journey Preference (Seeking a Lift/Offering a Lift/Both)" Font-Bold="true" Font-Size=8></asp:Label>
    <asp:RadioButtonList ID="rbJourneyP" runat="server" Font-size="8">
    <asp:ListItem>Seeking</asp:ListItem>
    <asp:ListItem>Offering</asp:ListItem>
    <asp:ListItem>Both</asp:ListItem>
    </asp:RadioButtonList>

ASPX.CS File

 protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection myConn = new SqlConnection();
        myConn.ConnectionString = "Data Source=XG7;Initial Catalog=Car_Share_XG;Integrated Security=True";
        myConn.Open();
        SqlCommand command = new SqlCommand();
        command.CommandText = "SELECT * FROM tbl_Member";
        command.CommandType = CommandType.Text;
        command.Connection = myConn;
        SqlDataAdapter da = new SqlDataAdapter(command);
        DataSet ds = new DataSet();
        da.Fill(ds, "tbl_Member");

        // Get a FileStream object
        StreamWriter xmlDoc = new StreamWriter(Server.MapPath("./Data2.xml"), false);
        // WriteXml method to write an XML document
        ds.WriteXml(xmlDoc);
        xmlDoc.Close();
        myConn.Close();

        try
        {
            bool SmokeP = Profile.SmokeP;
            if (SmokeP)
                lblSmokeP.Text += "  : Currently a Smoker";
            else
                lblSmokeP.Text += " : Currently a Non-Smoker";
        }
        catch
        {
            lblSmokeP.Text += " : Currently Both";
        }

        try
        {
            bool GenderP = Profile.GenderP;
            
        }
        catch
        {
            lblGenderP.Text += " Both";
        }

        try
        {
            bool JourneyP = Profile.JourneyP;
           
        }
        catch
        {
            lblJourneyP.Text += " Both";
        }
    }

protected void btnSearch_Click(object sender, EventArgs e)
    {
        SqlConnection myConn = new SqlConnection();
        myConn.ConnectionString = "Data Source=XG7;Initial Catalog=Car_Share_XG;Integrated Security=True";
        myConn.Open();
        SqlCommand command = new SqlCommand();
        command.CommandText = "SELECT Member_Address FROM tbl_Member";
        command.CommandType = CommandType.Text;
        command.Connection = myConn;
        SqlDataAdapter da = new SqlDataAdapter(command);
        DataSet ds = new DataSet();
        da.Fill(ds, "tbl_Member");

        // Get a FileStream object
        StreamWriter xmlDoc = new StreamWriter(Server.MapPath("./out1.xml"), false);
        // WriteXml method to write an XML document
        ds.WriteXml(xmlDoc);
        xmlDoc.Close();
        myConn.Close();

        XmlDocument sourceDocument = new XmlDocument();
        sourceDocument.Load(Server.MapPath("./out1.xml"));

        XmlDocument outputDocument = new XmlDocument();
        XmlElement markers = outputDocument.CreateElement("markers", "");
        outputDocument.AppendChild(markers);
        // use ChildNodes[1] if a <?xml version='1.0' encoding='utf-8'?> is in data2.xml, otherwise ChildNodes[0]
        foreach (XmlNode node in sourceDocument.ChildNodes[0].ChildNodes)
        {
            XmlElement child = outputDocument.CreateElement("marker", "");
            XmlAttribute att = outputDocument.CreateAttribute("address", "");
            att.Value = node.ChildNodes[0].InnerText;
            child.Attributes.Append(att);
            markers.AppendChild(child);
        }
        outputDocument.Save(Server.MapPath("./out2.xml"));
        Profile.SmokeP = Boolean.Parse(rbSmokeP.SelectedValue);
        Profile.GenderP = Boolean.Parse(rbGenderP.SelectedValue);
        Profile.JourneyP = Boolean.Parse(rbJourneyP.SelectedValue);
        Profile.Save();
        Response.Redirect("SearchPage2.aspx");
    }

Open in new window

xmalcolmAsked:
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.

lazyberezovskyCommented:
Try System.Boolean as property type
0
xmalcolmAuthor Commented:
where do I put that? on the top of the aspx page along with the other 'Using' commands?
0
lazyberezovskyCommented:
Sorry, man. That won't help :(
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

xmalcolmAuthor Commented:
:(( any other ideas?
0
lazyberezovskyCommented:
Check
rbSmokeP.SelectedValue
rbGenderP.SelectedValue
rbJourneyP.SelectedValue

What type of this controls? What exactly you are trying to parse?
0
xmalcolmAuthor Commented:
Well they are radio buttons. For example - for SmokeP - user can only select Smoker or Non-Smoker or Both

These values will then be used so that the query returns results matching the preference selected by the user.

0
lazyberezovskyCommented:
If they are asp:Radiobatton, then just use
Profile.SmokeP = RadioButton1.Checked;
0
lazyberezovskyCommented:
In your case
Profile.SmokeP = rbSmokeP.Checked;
0
xmalcolmAuthor Commented:
I Tried that earlier but I get a red underline. Could my web config be wrong?

<add name="SmokeP" type="boolean"/>

Profile.SmokeP = rbSmokeP.Checked;

When I hover over 'Checked' it says System.Web.UI.WebControls.RadioButtonList does not contain a definition for 'Checked' .....
0
dshrivallabhCommented:
Profile.SmokeP = rbSmokeP.Selected;
0
dshrivallabhCommented:
Profile.SmokeP = (rbSmokeP.SelectedIndex = 1?True:False);
0
lazyberezovskyCommented:
Ah, man so you have radiobutton list, not simple radiobuttons.
Don't know your page code, but here is how to use rb list:

Profile.SmokeP = rbSmokeP.SelectedValue == "listItemName";
or
Profile.SmokeP = rbSmokeP.SelectedIndex == 0;
0

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
xmalcolmAuthor Commented:
Nope doesnt seem to work. It doesnt even come up on the list as soon as you put the dot after rbSmokeP. There is SelectedValue but then it shows this error: error CS0029: Cannot implicitly convert type 'string' to 'bool'. I then do it this way: Profile.SmokeP = Boolean.Parse(rbSmokeP.SelectedValue);

But get the error String was not recognized as a valid Boolean.

Please note: My radio buttons are 'RadioButtonList' instead of individual radio buttons with ID for each radio button.
0
lazyberezovskyCommented:
SelectedValue is the NAME of radio button list item. Not it's value
See my code above
0
Bob LearnedCommented:
I believe that what you are looking for is this:

Profile.SmokeP = (rbSmokeP.SelectedItem.Text = "Smoker");
0
xmalcolmAuthor Commented:
Thanks the LearnedOne but Lazyberezovsky's solution worked or atleast i think its working :)). I am not getting an error message and my radio button stays selected on the preference I selected.

So thanks Lazyberezovsky. But now that I have done that, could you give me any ideas how I can use the stored preference to return results through a query. Currently I have:

SELECT Member_Address FROM tbl_Member

But what I need is SELECT Member_Address FROM tbl_Member WHERE (Preference selected is same as member preferences in tbl_member)

Any ideas?

0
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
ASP.NET

From novice to tech pro — start learning today.