Solved

MembershipUsers IsLockedOut List By UserName?

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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