首页 > 编程 > .NET > 正文

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

2024-07-10 13:19:23
字体:
来源:转载
供稿:网友

复制代码 代码如下:


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 = "";
}
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表