2

我正在尝试获取 userName 和 userID FromMembership.GetAllUsers()以将其绑定到下拉列表

   private void Bind_usersList()
    {
        var dictionary = Membership.GetAllUsers().Cast<MembershipUser>();
    }
4

1 回答 1

4

AMembershipUser没有“userID”,但 aProviderUserKey可能是Guid(fe in SqlMembershipProvider)。

这应该有效:

MembershipUserCollection members = Membership.GetAllUsers();
DdlUsers.DataSource = members.Cast<MembershipUser>()
    .ToDictionary(m => m.ProviderUserKey, m =>  m.UserName);
DdlUsers.DataValueField = "Key";
DdlUsers.DataTextField = "Value";
DdlUsers.DataBind();
于 2012-12-14T16:39:21.883 回答