获取 ListItem 中的值

get the value in ListItem

我试图从 DropDown 列表中的所有 ListItems 中获取值,但是当我将它们视为控件时,出现错误:

cannot convert type 'system.web.ui.control' to 'system.web.ui.webcontrols.listitem'

我的代码:

if (c.GetType() == typeof(ListItem))
 string id = c.ID;
 string value = ((ListItem)(c)).Value; ///I get the error here (ListItem)(c)

如何获得这些值?我想在不知道这些元素的 ID 的情况下执行此操作。

你能试试这个吗?

foreach (var item in ctl.Items) 
{
    var value = item.Value;
}