Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-14
1
Medium Priority
?
581 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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