Solved

MembershipUsers IsLockedOut List By UserName?

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

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…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

728 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