Solved

MembershipUsers IsLockedOut List By UserName?

Posted on 2009-04-13
2
242 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now