yah*_* kh 6 c# asp.net visual-studio-2010
一个我从未解决过的问题.我将用两个代码示例进行说明,其中一个工作,另一个不工作:
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();
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
第一个DropDownList填充没有任何错误,因为每个对象oFamilyFontList都有一个属性'Name',它与DataText和DataValue字段绑定.
第二个没有任何属性,它只是一个字符串数组.我可以在两个字段内放置什么来使其工作?
是的,你可以绑定一个数组,但你必须删除DataTextField和DataValueField属性
<asp:DropDownList
ID="DropDownList_FontColor"
runat="server">
</asp:DropDownList>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17679 次 |
| 最近记录: |