是否可以将下拉列表的DataValue字段中的所有值都输入到数组中?我试图将DataValues存储到一个数组中,稍后将其用于某些验证目的。
DropDownList dropDownList = new DropDownList();
dropDownList.ID = "dropDownEmployees";
dropDownList.DataSource = sqlDS;
dropDownList.DataTextField = "Employee";
dropDownList.DataValueField = "Employee_Name";
答案 0 :(得分:1)
string[] values = dropDownList.Items.Cast<ListItem>()
.Select(i => i.Value)
.ToArray();