I have a dropdownlist (specialty) and I want to loop through the number of options in the specialty and add it an array:
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.
}
So let's say the specialty dropdownlist has:
All
Card
Intern
Rad
The array should be:
strSpecArrayForTopics[0] = "All";
strSpecArrayForTopics[1] = "Card";
strSpecArrayForTopics[2] = "Intern";
strSpecArrayForTopics[4] = "Rad";