Author: Rob Frame | Posted on: 4/30/2010 6:05:12 PM | Views : 869

I am running into some additional difficulties with dropdown lists, and I'm hoping you can correct my thinking.
I have a table populated with items;  ITEM_ID, ITEM_NAME, ITEM_COST.
Here is my code:
DataClassesDataContext db = new DataClassesDataContext(); var c1 = from c in db.ITEMS select c; foreach (ITEM c2 in c1) { DropDownList1.Text = c2.ITEM_NAME; DropDownList1.DataValueField = c2.ITEM_ID.ToString(); } DropDownList1.DataSource = c1; DropDownList1.DataBind();


With this code I get this error:  DataBinding: 'ITEM' does not contain a property with the name '2'.
If I remove the assignment of DataSource to c1, the dropdown generates this error:  'DropDownList3' has a SelectedValue which is invalid because it does not exist in the list of item ...

Go to the complete details ...