Solved

MembershipUsers IsLockedOut List By UserName?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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