我在这里有这个代码,我试图将组合框的内容输出到我的标签。但是我得到一个错误,我无法将char转换为System.Web.UI.WebControls.ListItem
foreach (ListItem mine in ListSitesDropDownBox.Items)
{
Mylabel.Text += mine.Value.ToString() + " " + mine.ToString() + "<br>";
}
您如何建议我这样做以便输出列表项的值和名称?
由于
答案 0 :(得分:1)
你为什么这样做:
ListSitesDropDownBox.ToString()
<强> ??? 强>
只需将其替换为:
ListSitesDropDownBox.Items
答案 1 :(得分:1)
在第二部分中,您需要我的Text
属性。
foreach (ListItem mine in ListSitesDropDownBox.Items)
{
Mylabel.Text += mine.Value + " " + mine.Text + "<br>";
}
Here's the MSDN reference for ListItem。 ToString
也不需要Value
,因为它已经是string
。