[Webinar] Streamline your web hosting managementRegister Today

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

AND between 2 integers

Hi

I would like to create apermision sensitive menu. when the user logs on his system mermisions are loaded from a database. I then iterate through the menu options to see if the menuitem must be enabled or disabled. I wanted to do this by setting a value in the tag field of the menuitem at creation. If the iser option AND the tag field is true enable the menu.
The following code gives me an error. what is the correct way to do this.

        private void SetPermissions(MenuItem Menu, int PerValue)
            {
            foreach (MenuItem MI in Menu.MenuItems)
            {
                if (MI.MenuItems.Count > 0)
                    SetPermissions(MI, PerValue);

                if (MI.Tag != null)
                {
                    int TagValue = MI.Tag == null ? 0 : Convert.ToInt32(MI.Tag);

                    if ((TagValue & PerValue))
                        MI.Enabled = true;
                    else
                        MI.Enabled = false;
                }
            }
            }

Thanks
0
tcss
Asked:
tcss
  • 3
  • 2
1 Solution
 
NightmanCTOCommented:
I imagine that the error is that you can't implicitly convert the type int to a bool

Try this

if ((TagValue & PerValue)!=0)
0
 
tcssAuthor Commented:
Nice to have my question answered by a fellow countryman.
Gauteng
Centurion
0
 
NightmanCTOCommented:
Nice to know that I am not the only South African on EE tonight. I thought that most of the others would have slunk off and hidden away after the rugby this weekend.
0
 
tcssAuthor Commented:
No comment. Will not embarrass myself on a public forum. :-)
0
 
NightmanCTOCommented:
lol
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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