In my IOS application, I need to show a drop-down menu when the menu button is pressed and hide it when the menu button is pressed again. I tried changing the hidden status to false and true as in the code below however that doesn't seem to work.
if (menuButtonActive == false)
{
menuButtonActive = true;
DropMenu.Hidden = true;
}
if (menuButtonActive == true)
{
menuButtonActive = false;
DropMenu.Hidden = false;
}
Thanks to anyone that helps!
It's just simple, try this:
In Swift:
yourView.isHidden = true //or false
In Objective-C:
yourView.hidden = YES; //or NO;
In C#:
yourView.Hidden = true; //or false;
In your case you are doing it right, but the problem is you are using only if in both cases. You have to use else if for second if condition in order to achieve the desired result.
Otherwise the second if condition will be always true and get executed you will see no effect of first if block.
For Your Case:
It should be like:
menuButtonActive = !menuButtonActive
DropMenu.Hidden = menuButtonActive
Hope this help you! :)
It must be simple
menuButtonActive = !menuButtonActive;
DropMenu.Hidden = menuButtonActive;
look at follow code , add a else
if (menuButtonActive == false)
{
menuButtonActive = true;
DropMenu.Hidden = true;
}
else if (menuButtonActive == true)
{
menuButtonActive = false;
DropMenu.Hidden = false;
}
Related
I'm beginner & I need help
I try this code for check the id for employee to enable or disable the checkbox depend on the id for employee but the checkbox was disabled even when I login with the same Id in the session
if (Session["employeeNo"] == "12345")
{
CheckBoxList1.Enabled = true;
}
else
{
CheckBoxList1.Enabled = false;
}
If u r using CheckBox instead of Checkboxlist ...Try this Code It will Work
if (Session["employeeNo"].ToString() == "12345")
{
CheckBox1.Checked = true; // for Check
CheckBox1.Enabled = true; // for Enable
}
else
{
CheckBox1.Checked = false; // for UnCheck
CheckBox1.Enabled = false; // for Disable
}
The Session["employeeNo"] gives you an object, if you compare this with a string value the result will be false always. You have to convert this to string in order to compare with a string value, change the condition like this:
if (Session["employeeNo"].ToString() == "12345")
I got a little problem. I got a if statement which says if Session isn't equal 3, then do something, and if that isn't true, then do something else. My problem is just, that it isn't working proberly.
I've already tried:
1)
if (Session["userrank"] != "3")
{
pnlAdmin.Visible = false;
}
else
{
pnlAdmin.Visible = true;
}
2)
if (Session["userrank"].ToString() != "3")
{
pnlAdmin.Visible = false;
}
else
{
pnlAdmin.Visible = true;
}
3)
if ((string)Session["userrank"] != "3")
{
pnlAdmin.Visible = false;
}
else
{
pnlAdmin.Visible = true;
}
4)
if (((string)Session["userrank"]) != "3")
{
pnlAdmin.Visible = false;
}
else
{
pnlAdmin.Visible = true;
}
but none of them seems to work. And i have already checked if there's a Session called userrank that is getting the result 3.
sorry for the "stupid" question. I'm kind of new to C# & ASP.net.
Best Regards,
Anton
Your code sets pnlAdmin.Visible = false; if whatever is in Session["userrank"] is not 3.
It sets pnlAdmin.Visible = true; if whatever is in Session["userrank"] is 3.
You said it is 3; therefore, the panel should be visible. And that seems to be what is happening.
hi i would like to know how can i check if any of the reviewBtn is visible in the gridview and if ANY reviewBtn is present, btn_reviewAll will be visible.
currently the code below only shows the btn_reviewAll when ALL reviewBtn is visible. pls advise thanks!
foreach (GridViewRow row in GridViewReview.Rows)
{
Control reviewBtn = row.FindControl("ButtonReview") as Button;
if (reviewBtn.Visible == true)
{
btn_reviewAll.Visible = true;
}
else
{
btn_reviewAll.Visible = false;
}
}
change your code like this
foreach (GridViewRow row in GridViewReview.Rows)
{
Control reviewBtn = row.FindControl("ButtonReview") as Button;
if (reviewBtn.Visible == true)
{
btn_reviewAll.Visible = true;
break;
}
else
{
btn_reviewAll.Visible = false;
}
}
what it does is when one reviewBtn is visible it will set btn_reviewAll to visible and break out the foreach loop
#Shreesha's answer is absolutely correct, you can also do with less code using LINQ like this:-
if (GridViewReview.Rows.OfType<GridViewRow>()
.Any(b => ((Button)b.FindControl("ButtonReview")).Visible))
btn_reviewAll.Visible = true;
else
btn_reviewAll.Visible = false;
i am trying to make a program in c#, in which the values of check boxes are retrieved from csv file.I have 4 check boxes and all of them are true or false according to the conditions in csv file. My question is i am using
if (strProg[a] == "JC")
{
chkJogging.Checked = true;
chkCycling.Checked = true;
}
else if(strProg[a] =="C")
{
chkCycling == true
}
else if(strProg[a] == "WK")
{
chkWeightLoss.Checked = true;
chkKoxing.Checked = true
}
else
{
chkBoxing.Checked = false;
chkJogging.Checked = false;
chkCycling.Checked = false;
chkWeightLoss.Checked = false
}
But for some reason the last one 'else' loop is not working. Thanks.
Don't use IF-ELSE This way.
read this : SWITCH-CASE
try this :
switch (strProg[a])
{
case "JC":
chkJogging.Checked = true;
chkCycling.Checked = true;
break;
case "C":
chkCycling.Checked = true;
break;
case "WK":
chkWeightLoss.Checked = true;
chkKoxing.Checked = true;
break;
default:
chkBoxing.Checked = false;
chkJogging.Checked = false;
chkCycling.Checked = false;
chkWeightLoss.Checked = false;
break;
}
you are missing '.Checked' here, so my guess is probably your code is breakin at this point.
else if(strProg[a] =="C")
{
chkCycling == true
}
try to change it with
else if(strProg[a] =="C")
{
chkCycling.Checked == true
}
and see if it works.
I'm trying to insert a value into a RadioButton based on a value I have in an array.
This is what I'm trying to acheive, but I can't seem to get it work.
I know the IsChecked is a check if the RadioButton is checked or not, but I want to describe the means.
if (arrAnswer[nAnswerNum] == 0)
{
radioTrue.IsChecked = false;
radioFalse.IsChecked = false;
}
else if (arrAnswer[nAnswerNum] == 1)
{
radioTrue.IsChecked = true;
}
else if (arrAnswer[nAnswerNum] == 2)
{
radioFalse.IsChecked = true;
}
Thanks
Do it like this, it's much simpler
radioTrue.IsChecked = arrAnswer[nAnswerNum] == 1;
radioFalse.IsChecked = arrAnswer[nAnswerNum] == 2;
also dont forget to check if the index does exists to prevent indexoutofrange exception