我有以下代码:
foreach (Control c in myControl.Controls)
{
if(c.GetType().Equals(typeof(HtmlGenericControl)))
{
//do something
}
}
我的问题是 UL 和 DIV 标签都被视为 HtmlGenericControl。我可以添加另一个条件,以便只有 DIV 进入 if 语句吗?
最佳答案
检查 TagName属性:
foreach (Control c in myControl.Controls)
{
if(c.GetType().Equals(typeof(HtmlGenericControl)) &&
string.Equals((HtmlGenericControl)c).TagName, "div", StringComparison.OrdinalIgnoreCase)
{
//do something
}
}
关于c# - 如何区分作为 DIV 的 HtmlGenericControl 和作为 UL 的 HtmlGenericControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5837735/