在webform中清空多个控件的值的简单方法

在项目开发时候,有时候编辑界面上有多个控件的值要清楚的时候,直接用"控件ID.Text = """的方法就很麻烦了,呵呵,以前就是这样用,真是孤陋寡闻,^.^

///

1<summary>   
2/// 清空控件,清空指定的TextBox和Lale   
3/// </summary>

private void ClearControl()
{

//查找Form1中所有的控件
foreach(Control ct in this.FindControl("Form1").Controls)
{
if (ct is TextBox)
{
TextBox tb=(TextBox)ct;

//如果TextBox的名称不是TextBox1,则清楚控件的值
if(tb.ClientID !="TextBox1")
tb.Text = "";
}
if(ct is Label)
{
Label lb = (Label)ct;
lb.Text = "";
}
}
}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus