atrljoe
atrljoe

Reputation: 8151

ComboBox ListItem Help

I have this code here, I am trying to output the contents of a combobox, to my label. But I get an error that I cannot convert char to System.Web.UI.WebControls.ListItem

     foreach (ListItem mine in ListSitesDropDownBox.Items)
      {
       Mylabel.Text += mine.Value.ToString() + " " + mine.ToString() + "<br>";
      }

How would you suggest I go about doing this so that I can output the value and name of the list item?

Thanks

Upvotes: 0

Views: 578

Answers (2)

Benjamin Autin
Benjamin Autin

Reputation: 4171

You want the Text property of mine in the second part.

  foreach (ListItem mine in ListSitesDropDownBox.Items)
  {
    Mylabel.Text += mine.Value + " " + mine.Text + "<br>";
  }

Here's the MSDN reference for ListItem. Also ToString is unnecessary for Value as it is already a string.

Upvotes: 1

Davide Piras
Davide Piras

Reputation: 44595

why are you doing this:

ListSitesDropDownBox.ToString()

???

just replace it with:

ListSitesDropDownBox.Items

Upvotes: 1

Related Questions