A question that I never solved. I will illustrate with two code examples in which one works and the other does not:
Page_Load() { FontFamily[] oFamilyFontList = FontFamily.Families; DropDownList_Fonts.DataSource = oFamilyFontList; DropDownList_Fonts.DataBind(); string[] colorName = System.Enum.GetNames(typeof(KnownColor)); DropDownList_FontColor.DataSource = colorName; DropDownList_FontColor.DataBind(); }
<asp:DropDownList ID="DropDownList_Fonts" DataTextField="Name" DataValueField="Name" runat="server" > </asp:DropDownList> <asp:DropDownList ID="DropDownList_FontColor" DataTextField="colorName" DataValueField="colorName" runat="server" > </asp:DropDownList>
The first DropDownList fills everything without errors, because each oFamilyFontList object has a "Name" property that is associated with the DataText and DataValue fields.
The second one has no properties at all, and it's just an array of strings. What can I put in both fields to make it work?
source share