Take the 2-minute tour ×

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;

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.


I know what the exception means, but a pair object does contain the First and Second properties, that's where the problem lies.

share|improve this question

4 Answers 4

up vote 7 down vote accepted

First and Second are Fields not properties of Pair type. You need to create a class with two properties:

 public class NewPair
    public string First { get; set; }
    public string Second { get; set; }

EDIT: Use of Tuple : suggested by @Damien_The_Unbeliever & @Chris Chilvers

List<Tuple<string, string>> list = new List<Tuple<string, string>>()
   new Tuple<string,string>("One","1"),
   new Tuple<string,string>("Two","2"),

ddlGraphType.DataTextField = "Item1";
ddlGraphType.DataValueField = "Item2";

ddlGraphType.DataSource = list;
share|improve this answer
Alternatively, in .net 4 you can use Tuple<string, string> –  Chris Chilvers Nov 24 '11 at 13:35
For .NET 4 or later, Tuple<T1,T2> might be a suitable replacement - it does implement properties rather than fields. –  Damien_The_Unbeliever Nov 24 '11 at 13:35
Nice one Chris and Damien! –  ThePower Nov 24 '11 at 13:44
@Damien_The_Unbeliever & Chris Chilvers Thanks buddy! I appreciate your suggestion. –  AVD Nov 24 '11 at 13:45

Theat means the target property must be a dependency property. This also means that you cannot bind a field and Pair.First is field not property

share|improve this answer
public sealed class Pair


Public field    First   Gets or sets the first object of the object pair.
Public field    Second  Gets or sets the second object of the object pair.


share|improve this answer

Probably you've forgot the {get; set;} after declaring the properties.

public class A

  //This is not a property
  public string Str;

 //This is a property
  public string Str2 {get; set;}

share|improve this answer

Your Answer


