foreach (Control control in this.Form.Controls)
{
if (control is System.Web.UI.WebControls.TextBox)
{
TextBox txt = (TextBox)control;
txt.Text = String.Empty ;
}
}
//代码简写
foreach (Control control in this.Form.Controls)
{
TextBox t = control as System.Web.UI.WebControls.TextBox;
if (t != null)
{
t.Text = String.Empty;
}
}
//举一反三,此程序可应用于大多数.NET服务器控件
本文介绍了一种简化方法来批量清除ASP.NET服务器控件的默认值,包括使用foreach循环和类型转换技巧,适用于多种.NET服务器控件。
816

被折叠的 条评论
为什么被折叠?



