I'm trying to get a list of usernames and bind them to a DropDownList and I must be missing a trick because I can't seem to cast it to the correct type. The code is below and the title is the error message I'm recieving.
EDIT - QUser inherits from MembershipUser
UserRepository userRepository = new UserRepository();
// retrieve custom user objects
IEnumerable<QUser> Users = userRepository.GetAllUsers();
// just get usernames only
IEnumerable<string> userList = (from u in Users select u.UserName);
// set usernames to data source for a DropDownList
Username.DataSource = userList.ToArray(); // Cast error occurs here
Username.DataBind();
I've also tried casting the IEnumerable using the cast method as follows with no luck:
userList.Cast<string>().ToArray();
EDIT:
QUser Class
public class QUser : MembershipUser
{
public QUser(){}
public QUser(MembershipUser user):
base(user.ProviderName, user.UserName, user.ProviderUserKey, user.Email,
user.PasswordQuestion, user.Comment, user.IsApproved, user.IsLockedOut,user.CreationDate,
user.LastLoginDate,user.LastActivityDate,user.LastPasswordChangedDate,user.LastLockoutDate)
{}
public string Forename
{
get;set;
}
public string Surname
{
get;set;
}
public string Phone
{
get;set;
}
public string PropertyNameNumber
{
get;set;
}
public string Street
{
get; set;
}
public string Town
{
get; set;
}
public string Area
{
get; set;
}
public string Postcode
{
get; set;
}
public DateTime? ExpiredDate
{
get; set;
}
}