asp.net中获取某种控件在页面中的数量

以label控件为例:
int LabelCount = GetLabelCount(this);//获取Literal控件在本页面的数量
private int GetLabelCount(System.Web.UI.Control parentCountol)//获取某种控件在页面中的数量
{
int LabelCount = 0;
foreach (System.Web.UI.Control c in parentCountol.Controls)
{
if (c is System.Web.UI.WebControls.Label)
{
LabelCount++;
}
LabelCount += GetLabelCount(c);
}
return LabelCount;
}
版权声明:
作者:东明兄
链接:https://blog.crazyming.com/note/158/
来源:CrazyMing
文章版权归作者所有,未经允许请勿转载。


共有 0 条评论