我有一個下拉列表(specialty
),我通過在專業的選擇人數要循環,並將其添加一個數組:如何將項目從下拉列表添加到字符串數組
string[] strSpecArrayForTopics = new string[Specialty.Items.Count]; //total number of specialty items
foreach (ListItem li in Specialty.Items) //for each item in the dropdownlist
{
strSpecArrayForTopics[Specialty.Items.Count] = li.Value; //add the value to the array (The error happens here)
lblSpec.Text = lblSpec.Text + "<br />" + li.Value; //this works fine.
}
所以我們說專業下拉列表具有:
All
Card
Intern
Rad
陣列應該是:
strSpecArrayForTopics[0] = "All";
strSpecArrayForTopics[1] = "Card";
strSpecArrayForTopics[2] = "Intern";
strSpecArrayForTopics[4] = "Rad";
你的問題是什麼?什麼是錯誤? 想想那個,我想你可能會自己動手...... – Xeun