Solved

making a checkbox checked...

Posted on 2007-03-23
12
230 Views
Last Modified: 2010-04-16
Hi I'm trying to get a checkbox to be checked depending on something but I dont know how to do this... for example

                if (Onsite == "Yes")
                {
                    CheckBoxAvail.Checked == true;
                }
0
Comment
Question by:stellyuk
12 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
You are making an equality check with two equals signs "==".

You need an assignment, which is just one equals sign:

    CheckBoxAvail.Checked = true;

0
 

Author Comment

by:stellyuk
Comment Utility
HIi...
thanks for that but it doesn't work..

                string Avail = Comp["Available"].ToString();

                if (Avail == "Yes")
                {
                    CheckBoxAvail.Checked = true;
                }

I'm getting the information from a SQL dataset and its still not working... any ideas why??

Stelly
0
 

Author Comment

by:stellyuk
Comment Utility
Even tried this...

                string Avail = "Yes";

                if (Avail == "Yes")
                {
                    CheckBoxAvail.Checked = true;
                }
                else
                {
                    CheckBoxAvail.Checked = false;
                }

Stelly
0
 

Author Comment

by:stellyuk
Comment Utility
Anyone please??

I really need this done urgently

Thanks,

Stelly
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
I don't see anything wrong with the CheckBox assignment and unfortunately I don't work with DBs very much.

Is this by chance a WebForm?...I don't work with those either.  =\
0
 

Author Comment

by:stellyuk
Comment Utility
yes it is a webform... dam dam dam... anyone else??

Stelly
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:stellyuk
Comment Utility
Ok works with
                string Avail = "Yes";

                Response.Write(Avail);

                if (Avail == "Yes")
                {
                    CheckBoxAvail.Checked=true;
                }

but as soon as I use this line

string Avail = Comp["Available"].ToString();

it does not work

Stelly
   
0
 

Author Comment

by:stellyuk
Comment Utility
   protected void Page_Load(object sender, EventArgs e)
    {
        int PCID = Convert.ToInt32(Request.QueryString["pcid"]);

        DataSet CompSet = SQLQueries.CompDetailBindData(PCID);

        string sPCIDValue = Convert.ToString(PCID);



            if (null != CompSet && 0 < CompSet.Tables[0].Rows.Count)
            {
                DataRow Comp = CompSet.Tables[0].Rows[0];

                LabelCompModel.Text = Comp["PcModel"].ToString();
                TextBoxCCCSR.Text = Comp["CCCSR"].ToString();
                TextBoxEPSR.Text = Comp["EPSR"].ToString();
                TextBoxShipDate.Text = Comp["ShipDate"].ToString();
                LabelOnsite.Text = Comp["OnSite"].ToString();
                LabelUser.Text = Comp["UserID"].ToString();

                string Avail = Comp["Available"].ToString();
               
                //string Avail = "Yes";

                Response.Write(Avail);

                if (Avail == "Yes")
                {
                    CheckBoxAvail.Checked = true;
                }
                else
                {
                    CheckBoxAvail.Checked = false;
                }
   

            }
        }
       
thats all the code for you

Stelly
0
 
LVL 8

Expert Comment

by:RickJ
Comment Utility
What type of field is "Available"?
After you do this,
string Avail = Comp["Available"].ToString();
is the value of Avail defintiely "Yes"?
0
 
LVL 4

Expert Comment

by:g_johnson
Comment Utility
try setCheckedstate  = true
0
 
LVL 12

Accepted Solution

by:
Sinoj Sebastian earned 500 total points
Comment Utility
What is the out put of  "Response.Write(Avail);"?
"==" operator over string is case sensitive.
If you are sure 'Avail' is always lowercase, use  if (Avail == "yes")

or try 'if(string.Compare(Avail,"Yes", true)==0)'
0
 

Author Comment

by:stellyuk
Comment Utility
Hi there,

Changed the string to a integer and works fine now..

Stelly
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now