In csharp, I want the button to appear whenever I want and disappear whenever I want

34 Views Asked by At

I tried this way, but the button does not appear even though the items are larger than 0.

enter image description here

How can I do this?

2

There are 2 best solutions below

0
pavel kirichenko On

Try add

else
{
    btnRemoveToCart.Visible = true;
}
0
Joel Coehoorn On

It's not enough to set it to false if you don't want it to show. You also need to set it to true when you want to see it again. But you can write one line that does both:

btnRemoveToCart.Visible = (lbxCart.Items.Count > 0);

Now we also no longer need the if() check.