简体   繁体   English

c#ASP.NET成员身份问题

[英]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. 我希望MemberList列表框显示我的成员资格数据库中的所有用户名。 but I can't seem to get it working correctly 但我似乎无法让它正常工作

Membership.GetAllUsers() returns a collection of users. Membership.GetAllUsers()返回一组用户。 If you call .ToString() on that collection you will not automatically get all user names. 如果在该集合上调用.ToString() ,则不会自动获取所有用户名。 Instead you will get the name of the collection class itself ( MembershipUserCollection ). 相反,您将获得集合类本身的名称( 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 ). 您可以通过设置DataTextField属性来指定要在控件中显示的每个成员的属性(我选择“UserName”,但您可以选择任何MembershipUser属性 )。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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