I’m data binding a list of pairs to a drop down list, for some reason it’s not working and I’m intrigued.
The code I am using is :
public void BindDropDown(List<Pair> dataList)
{
ddlGraphType.DataTextField = "First";
ddlGraphType.DataValueField = "Second";
ddlGraphType.DataSource = dataList;
ddlGraphType.DataBind();
}
I’m getting this exception, which is a lie!
DataBinding: 'System.Web.UI.Pair' does not contain a property with the name 'First'.
Thanks in advance.
Added
I know what the exception means, but a pair object does contain the First and Second properties, that’s where the problem lies.
FirstandSecondare Fields not properties ofPairtype. You need to create a class with two properties:EDIT: Use of Tuple : suggested by @Damien_The_Unbeliever & @Chris Chilvers