Como preencher um DropDownList usando um List <ListItem>
Eu tenho um DropDownList.
Preciso preenchê-lo com o item coletado em umList<ListItem>
.
No meu script, o coletor foi preenchido corretamente.
Mas não consigo preencher o DropDownList. Eu recebo um erro:
DataBinding: 'System.Web.UI.WebControls.ListItem' does not contain a property with the name 'UserName'."}
<asp:DropDownList ID="uxListUsers" runat="server" DataTextField="UserName"
DataValueField="UserId">
List<ListItem> myListUsersInRoles = new List<ListItem>();
foreach (aspnet_Users myUser in context.aspnet_Users)
{
// Use of navigation Property EntitySet
if (myUser.aspnet_Roles.Any(r => r.RoleName == "CMS-AUTHOR" || r.RoleName == "CMS-EDITOR"))
myListUsersInRoles.Add(new ListItem(myUser.UserName.ToString(), myUser.UserId.ToString()));
}
uxListUsers.DataSource = myListUsersInRoles; // MAYBE PROBLEM HERE????
uxListUsers.DataBind();
Alguma ideia? obrigado