Solved

how to use Roles.GetUsersInRole by selecting roles from checkbox list

Posted on 2009-04-14
1
572 Views
Last Modified: 2012-05-06
I have app using standard roles and membership.  I have checkbox that is populated with all roles like this

           checkbox1.DataSource = Roles.GetAllRoles();
           checkbox1.DataBind();

I want to check a number of roles on the checkbox and if the role is selected then add all usernames to a list.  Something like

foreach (ListItem theseRoles in checkbox.Items)
            {
                if (checkbox.Selected)

//then add all the usernames to the list

listofUserNames = new List<string>(Roles.GetUsersInRole(checkbox.text));

//and so on adding all the usernames to the list for each checkbox role checked.

How can I implement this?
0
Comment
Question by:mugsey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 500 total points
ID: 24144643
Hi mugsey,
>>.. I want to check a number of roles on the checkbox and if the role is selected then add all usernames to a list.
Try this:

Further details:
http://www.4guysfromrolla.com/demos/printPage.aspx?path=/articles/052307-1.aspx

             int i;
            // Get all of the users
             MembershipUserCollection allUsers = Membership.GetAllUsers();
             MembershipUserCollection filteredUsers = new MembershipUserCollection();
 
             for (i = 0; i < checkbox1.Items.Count; i++)
             {
                 if (checkbox1.Items[i].Selected)
                 {
                     // If we are filtering by role, get the users in the specified role
                     string[] usersInRole = Roles.GetUsersInRole(checkbox1.Items[i].Value);
   
                     // For each user in the role, add the user details to filteredUsers
                     foreach (MembershipUser user in allUsers)
                     {
                        foreach (string userInRole in usersInRole)
                         {
                            if (userInRole == user.UserName)
                            {
                              filteredUsers.Add(user);
                              break; // Breaks out of the inner foreach loop to avoid unneeded checking.
                            }
                         }
                     }
                 }
             }

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question