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

making a checkbox checked...

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
stellyuk
Asked:
stellyuk
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You are making an equality check with two equals signs "==".

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

    CheckBoxAvail.Checked = true;

0
 
stellyukAuthor Commented:
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
 
stellyukAuthor Commented:
Even tried this...

                string Avail = "Yes";

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

Stelly
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
stellyukAuthor Commented:
Anyone please??

I really need this done urgently

Thanks,

Stelly
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
stellyukAuthor Commented:
yes it is a webform... dam dam dam... anyone else??

Stelly
0
 
stellyukAuthor Commented:
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
 
stellyukAuthor Commented:
   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
 
RickJCommented:
What type of field is "Available"?
After you do this,
string Avail = Comp["Available"].ToString();
is the value of Avail defintiely "Yes"?
0
 
g_johnsonCommented:
try setCheckedstate  = true
0
 
Sinoj SebastianCommented:
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
 
stellyukAuthor Commented:
Hi there,

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

Stelly
0

Featured Post

Independent Software Vendors: 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!

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