Duplicating DropDownListItems Without Looping

非 Y 不嫁゛ 提交于 2020-01-14 05:09:39

问题


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:


Does this work?

DropDownList2.DataSource = DropDownList1.Items;
DropDownList2.DataTextField = "Text";
DropDownList2.DataValueField = "Value";
DropDownList2.DataBind();



回答2:


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



来源:https://stackoverflow.com/questions/1162409/duplicating-dropdownlistitems-without-looping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!