ASP.NET 10个LABLE标签如何批处理

来源:百度知道 编辑:UC知道 时间:2024/06/23 03:29:07
LABLE标签ID为LABLE1--LABLE10;
如何用FOR循环让它们都为空;
FOR (int i=0;i<11;i++)
{
这里怎么写?
}
能不能详细点呢?

((Label)this.FindControl(string.format("Label{0}",i))).Text = "";

给你批量清空textbox的例子,相应的改动下就好了
private void Button1_Click(object sender, System.EventArgs e)
{
foreach (Control ctl in this.Controls)
{
this.txtClear(ctl);
}
}
private void txtClear(Control ctls)
{
if(ctls.HasControls())
{
foreach (Control ctl in ctls.Controls)
{
txtClear(ctl);
}
}
else
{
if (ctls.GetType().Name == "TextBox")
{
TextBox tb = new TextBox();
tb = (TextBox)this.FindControl(ctls.ID);
tb.Text = "";
}
// else if (ctls.GetType().Name == "DropDownList")
// {
// DropDownList ddl = new DropDownList();
// ddl = (DropDownList)this.FindControl(ctls.ID);
// ddl.SelectedIndex = 1;
// }
}
}

HasControls()