Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

971 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