【发布时间】:2011-02-01 16:04:24
【问题描述】:
我有一个下拉列表。
我需要用List<ListItem> 中收集的项目填充它。
在我的脚本中,收集器已正确填充。
但我无法填充 DropDownList。我收到一个错误:
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();
有什么想法吗?谢谢
【问题讨论】: