Solved

MembershipUsers IsLockedOut List By UserName?

Posted on 2009-04-13
2
249 Views
Last Modified: 2012-05-06
I cannot find an easy solution to simply fill a listbox with a list of users and each users IsLockedOut status. I was using the very adequate Membership.GetAllUsers() method to list just userNames. Here's my unsuccessful attempt to lists all users AND IsLockedOut status:

 void Page_Init(object sender, EventArgs e)
    {        
        lbxAllUsers.DataSource = GetAllUsersAndStatus(); // Membership.GetAllUsers();
        lbxAllUsers.DataMember = "UserName";
        lbxAllUsers.DataBind();

        lbxLockedOutStatus.DataSource = GetAllUsersAndStatus();
        lbxLockedOutStatus.DataMember = "LockedOut";
        lbxLockedOutStatus.DataBind();
    }
       
    protected DataSet GetAllUsersAndStatus()
    {
        DataSet ds = new DataSet();
        DataTable dt = new DataTable("Members");
        ds.Tables.Add(dt);
        DataColumn dcUserName = new DataColumn("UserName");
        DataColumn dcLockedOut = new DataColumn("LockedOut");
        dt.Columns.Add(dcUserName);
        dt.Columns.Add(dcLockedOut);
        DataRow row;

        MembershipUserCollection allUsers = Membership.GetAllUsers();

        foreach (MembershipUser user in allUsers)
        {
            row = dt.NewRow();
            row[dcUserName] = user.UserName;
            row[dcLockedOut] = user.IsLockedOut.ToString();
            dt.Rows.Add(row);
        }
        return ds;
    }
0
Comment
Question by:pointeman
[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
2 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 250 total points
ID: 24135549
Hi pointeman,
Quick fix, i've noticed the error that raised from the declared column name.
eg:
These lines:
 row[dcUserName] = user.UserName;
 row[dcLockedOut] = user.IsLockedOut.ToString();
           
Should returned as
 row["UserName"] = user.UserName;
 row["LockedOut"] = user.IsLockedOut.ToString();


0
 

Author Comment

by:pointeman
ID: 24170095
Two heads are better than one, thanks.....
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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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