我正在尝试从Membership.GetAllUsers()
获取userName和userID以将其绑定到下拉列表
private void Bind_usersList()
{
var dictionary = Membership.GetAllUsers().Cast<MembershipUser>();
}
答案 0 :(得分:4)
MembershipUser
没有“userID”,但ProviderUserKey
可能是Guid
(f {。在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();