当前位置:Gxlcms > asp.net > ASP.NET(C#)中遍历所有控件

ASP.NET(C#)中遍历所有控件

时间:2021-07-01 10:21:17 帮助过:96人阅读

代码如下:
for (int i = 0; i < this.Controls.Count; i++)
{
foreach (System.Web.UI.Control control in this.Controls[i].Controls)
{
if (control is TextBox)
(control as TextBox).Text = "";
}
}
foreach (Control cl in this.Page.FindControl("Form1").Controls)
{
if (cl.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
((TextBox)cl).Text = "";
}
}

人气教程排行