一个我一直没有解决的问题。我将用两个代码示例进行说明,其中一个可以工作,另一个则不能:
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 字段绑定的属性“Name”。
第二个根本没有任何属性,它只是一个字符串数组。我可以在这两个字段中放入什么以使其正常工作?
是的,你可以绑定一个数组,但你必须删除DataTextField
and DataValueField
属性
<asp:DropDownList
ID="DropDownList_FontColor"
runat="server">
</asp:DropDownList>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)