mercredi 21 octobre 2015

Or in if statement not working as expected

I have the following in my gridview's OnRowDataBound method:

protected void PerformanceGridOnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Guid userId;
        if (Guid.TryParse(e.Row.Cells[0].Text, out userId))
        {
            var membershipUser = Membership.GetUser(userId);
            if (membershipUser != null)
            {
                var userName = membershipUser.UserName;

                var isCrewManager = Roles.IsUserInRole(userName, "Crew Manager");
                var isCrewLeader = Roles.IsUserInRole(userName, "Crew Leader");
                var isCrewMan = Roles.IsUserInRole(userName, "Crew Man");
                var isLogistics = Roles.IsUserInRole(userName, "Logistics");
                var isAdmin = Roles.IsUserInRole(userName, "Administrator");

                if ( isCrewManager || isCrewLeader || isCrewMan || isLogistics || isAdmin)
                {
                    e.Row.Visible = false;
                }
            }
        }
    }
}

For some reason it never goes in, even when isCrewManager and isCrewLeader are true (the rest in this case are false). Why is this happening? Shouldn't it see the first true and go in without checking the rest? I've verified via debugging that the values for those are true/false as they should be but yeah, True or True or False or False or False is somehow resulting in false instead of true

Picture of values of booleans when debugging

Aucun commentaire:

Enregistrer un commentaire