构造函数问题 - 不会显示不同的文本和值的结果
问题描述:
我想获取下拉菜单的值和文本以显示相同数据的不同变体。值中的日期需要更多的机器可读性,但文本需要更人性化。目前,我有这样的:构造函数问题 - 不会显示不同的文本和值的结果
dateItems.Add(new ListItem(date.ToString("ddd, dd-MM-yyyy"), date.ToString("yyyy-MM-dd")));
}
recordDate.DataSource = dateItems;
recordDate.DataBind();
但最终的结果是,无论是文本和下拉列表中的值只显示代码的文本部分:
<option value="Sat, 16-09-2017">Sat, 16-09-2017</option>
我只是不当价值替代文本存在时,了解它们为什么相同。
任何想法,我已经做了什么来打破这一点非常受欢迎。
答
请更换
recordDate.DataSource = dateItems
recordDate.DataBind()
到
recordDate.DataValueField = "Value"
recordDate.DataTextField = "Text"
recordDate.DataSource = dateItems
recordDate.DataBind()
OMG!有那么容易...比你还要多。完美的作品'':-) – cloudseeker