G
Guest
How do I bind an arraylist of custom objects to a dropdownlist and set the datavaluefield and datatextfields?
Let's say I have an array of custom 'Person' objects.
public class Person
{
public string FirstName;
public string LastName;
.....
}
I want to bind an array of Person objects and use the DataTextField and DataValue field of the DropDown to bind:
ie:
....
ddList.DataSource = PersonObjectArray()
ddList.DataTextField = "FirstName";
ddList.DataValueField = "LastName"; ddList.DataBind();
Can this be done?
I've tried creating a PersonCollection class which inherits ArrayList but I'm still unsure how to access the properties of the objects within the arraylist to set the above values. Please help!
Let's say I have an array of custom 'Person' objects.
public class Person
{
public string FirstName;
public string LastName;
.....
}
I want to bind an array of Person objects and use the DataTextField and DataValue field of the DropDown to bind:
ie:
....
ddList.DataSource = PersonObjectArray()
ddList.DataTextField = "FirstName";
ddList.DataValueField = "LastName"; ddList.DataBind();
Can this be done?
I've tried creating a PersonCollection class which inherits ArrayList but I'm still unsure how to access the properties of the objects within the arraylist to set the above values. Please help!