我尝试了以下方法:
foreach (Control child in panel.Controls)
{
Response.Write("test1");
if (child.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButtonList"))
{
RadioButtonList r = (RadioButtonList)child;
Response.Write("test2");
}
}
我的页面上没有显示“test1”和“test2”。这意味着这个逻辑有问题。您有什么建议吗?
foreach (RadioButtonList list in panel.Controls.OfType<RadioButtonList>())
。只是提供一个FYI。但使用child.GetType().ToString()...
将是我想到的最后一种方法。例如,一个if
可能会说if (child is RadioButtonList)
。 - Anthony Pegram