我正在尝试从在列表中构建的字典中填充下拉列表,例如,列表是从事件类构建的(在示例中它已被削减了一点):
public class Events
{
public Events()
{
StartDate = new Dictionary<string, string>();
}
[DataMember(Name = "eventId")]
public Guid EventId { get; set; }
[DataMember(Name = "eventName")]
public string EventName { get; set; }
[DataMember(Name = "startDate")]
public Dictionary<string, string> StartDate { get; set; }
}
然后是实际的数据绑定:
protected void submitSearch_Click(object sender, EventArgs e)
{
if (IsValid)
{
IEnumerable<Events> events = EventProvider.FindEvents(eventName.Text);
eventSearchResults.DataSource = events;
eventSearchResults.DataBind();
}
}
在页面中我有:
<asp:TemplateField HeaderText="Start date">
<ItemTemplate>
<p>
<asp:Label ID="lblStartDate" Text="Start month/year" runat="server" /><br />
<asp:DropdownList ID="ddlStartDate" DataSource='<%# Eval("startDate") %>' runat="server" />
</p>
</ItemTemplate>
但是键和值都被添加到下拉列表中的值字段中。我哪里错了?任何示例将不胜感激。