I have
public class ListA
{
private string code;
private string name;
public string Code { get { return code; } set { code = value; } }
public string Name { get { return name; } set { name = value; } }
}
List<ListA> lst = new List<ListA>();
public List<ListA> getList()
{
lst.Add(new ListA { Code = "ABC", Name = "Smith" });
lst.Add(new ListA { Code = "XYZ", Name = "Abbey" });
return lst;
}
and in the dropdownlist I want ABC:Smith populated.
ddlList.DataTextField = "Name";
only populates the name.
I want to populate both name and code.
How do I do that. Please help.
It seems that the DataTextField can only be used to display a single property. You can either create a new property on ListA like the following:
or remove the DataTextField altogether and use
or create a new class which inherits from ListA and does one of the things I mentioned above for proper display.