例如,我有以下类声明的一个实例:
public class Person
{
public string Name = "";
public Dictionary<string, string> Properties = new Dictionary<string, string>();
}
我有一个我希望绑定到 Asp.NET 下拉列表的人员列表。
List<Person> people = new List<Person>();
//fill the list etc..
//bind to the drop down list
ddlPeople.DataSource = people;
ddlPeople.DataTextField = "Name";
ddlPeople.DataTextField = "Properties['Age']"; //this is what I would like!
年龄总是存在的。我无法控制 person 类。有谁知道我想做的事情是否可以实现?
谢谢!