views:

54

answers:

3

This works like a charm... loading DropDownList2 with all the items from DropDownList1 without looping:

DropDownList2.DataSource = DropDownList1.Items;
DropDownList2.DataBind();

But, the data from the item text of DropDownList1 is copied into both the text and value fields of DropDownList2. Is there anyway to get both the text and the value fields to populate properly?

+1  A: 

Does this work?

DropDownList2.DataSource = DropDownList1.Items;
DropDownList2.DataTextField = "Text";
DropDownList2.DataValueField = "Value";
DropDownList2.DataBind();
Ben M
Updated to reflect Spencer's suggestion, which makes sense.
Ben M
A: 

Try setting the DataValueField and DataTextField properties to "Value" and "Text" respectively. That should work.

Spencer Ruport
A: 

Thanks Ben and Spencer! Yes, that did the trick.