【发布时间】:2015-06-18 09:28:51
【问题描述】:
我试图从下拉列表中的所有 ListItems 中获取值,但是当我将它们视为控件时,我得到一个错误:
无法将类型“system.web.ui.control”转换为“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 的情况下这样做。
【问题讨论】:
-
是
cListItem 还是 DropDownList? -
c是控制foreach (Control c in ctl.Controls) { .... } -
是
ctl你的下拉菜单吗?
标签: c# asp.net webforms controls listitem