Duplicating DropDownListItems Without Looping

2019-05-30 07:12发布

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?

2条回答
▲ chillily
2楼-- · 2019-05-30 07:42

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

查看更多
何必那么认真
3楼-- · 2019-05-30 07:51

Does this work?

DropDownList2.DataSource = DropDownList1.Items;
DropDownList2.DataTextField = "Text";
DropDownList2.DataValueField = "Value";
DropDownList2.DataBind();
查看更多
登录 后发表回答