Reputation: 10608
In Asp.Net 3.5, it is possible that the DataValueField is a IList ?
myddl.DataValueField = "ListOfId"
where ListOfId as a IList in my DataSource
Upvotes: 1
Views: 6333
Reputation: 21
You have to pass the string name of the field you are assigning to the DataTextField and DataValueField before you DataBind() the DropDownList.
Example:
protected void populateDropDownList(){
IList<MyObject> myObjectList = getMyObjectList();
DropDownList1.DataSource = myObjectList;
DropDownList1.DataTextField = "FullName"; // exact name of field in class
DropDownList.DataValueField = "id";
DropDownList.DataBind();
}
Upvotes: 2
Reputation: 8166
It's not possible. DataValueField must be a string, that is the name of a public property of the binded datasource:
If you have a simple list of string you can just bind it to the dropdown:
C# - Dumping a list to a dropdownlist
Upvotes: 0