简体   繁体   中英

c# ASP.NET Membership issue

        NumberUsersOnlineLabel.Text = Membership.GetNumberOfUsersOnline().ToString();
        PasswordMinLengthLabel.Text = Membership.MinRequiredPasswordLength.ToString();
        PasswordMinNoAlphaNumericLabel.Text Membership.MinRequiredNonAlphanumericCharacters.ToString();
        TotalNumberofUsersLabel.Text = Membership.GetAllUsers().Count.ToString();

  MembersList.Text = Membership.GetAllUsers().ToString();

I would like the MemberList list box to display all user names in my membership db. but I can't seem to get it working correctly

Membership.GetAllUsers() returns a collection of users. If you call .ToString() on that collection you will not automatically get all user names. Instead you will get the name of the collection class itself ( MembershipUserCollection ).

Instead you want to display for each user the user's name for example. For this you need to use data binding to bind the collection of users to the list control. You can specify what property of each member to display in the control by setting the DataTextField property (I chose "UserName", but you can chose any of the MembershipUser properties ).

MembersList.DataTextField = "UserName";
MembersList.DataSource = Membership.GetAllUsers();
MembersList.DataBind();

您需要遍历GetAllUsers()返回的集合, GetAllUsers()用户名连接到StringBuilder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM