一个我从未解决的问题。我将举例说明两个代码样本,其中一个工作和其他不:将字符串数组绑定到DropDownList?
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>
第一个DropDownList填充不罚款,因为每个对象oFamilyFontList具有结合属性“名称”的错误与DataText和DataValue字段。
第二个没有任何属性,它只是一个字符串数组。我可能会在两个领域里面做些什么来使其发挥作用?
也许一个愚蠢的问题 - 但是 - 是否有在colorName阵列的任何值? – Fischermaen
当然有,AVD已经回答了我的问题。 –