I’d like to bind my dropdown to a generic list.
It seems really simple but I keep getting the error DataBinding: 'InternalPurchasingForms.Types.Item' does not contain a property with the name 'itemID'.
Here’s my code for the class:
namespace InternalPurchasingForms.Types
{
public class Item
{
public int itemID;
public String name;
//...
}
}
Here’s my dropdown databinding code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<Item> allItems = DataAccessLayer.getAllItems();
uxDropDownItemList.DataSource = allItems;
uxDropDownItemList.DataValueField = "itemID";
uxDropDownItemList.DataTextField = "name";
uxDropDownItemList.DataBind();
}
}
I want to tell the dropdown that the “value” for each line is Item.itemID and that the “text” is Item.Name, but ASP.NET’s telling me that those fields don’t exist inside Item. I’m able to access Item’s fields just fine elsewhere.
How do I do this correctly?
Make sure you are using a getter and setter in your Item class for itemID and name.