我将数据绑定到一个下拉列表对的列表,由于某种原因它不工作,我是感兴趣。DataBinding:'System.Web.UI.Pair'不包含名称为'First'的属性
我使用的代码是:
public void BindDropDown(List<Pair> dataList)
{
ddlGraphType.DataTextField = "First";
ddlGraphType.DataValueField = "Second";
ddlGraphType.DataSource = dataList;
ddlGraphType.DataBind();
}
我得到这个例外,这是骗人的!
DataBinding: 'System.Web.UI.Pair' does not contain a property with the name 'First'.
在此先感谢。
新增
我知道异常意味着什么,但一对对象不包含第一,第二属性,这就是问题所在。
或者,在.NET 4可以使用元组<字符串,字符串> –
对于.NET 4或更高,'元组'可能是一个合适的替代 - 它确实实现的属性而不是字段。 –
不错的克里斯和达米安! – ThePower