28,409
社区成员




protected void btSearch_Click(object sender, EventArgs e)
{
//先进行清空-----------------
///Control ctrl =new Control();
foreach (Control ctrl in Page.Controls)
{
if (ctrl.GetType()==typeof(Label))
((Label)ctrl).Text = "";
}
//以下语句有执行.....可以在页面上看到清除了DATAGRID的数据
dgOtherOutB.DataSource = null;
dgOtherOutB.DataBind();
//.................以下代码省略
}
//递归清空Label
//调用:ClearAllLabel(Page.Controls);
private void ClearAllLabel(ControlCollection ctls)
{
foreach (Control ctrl in ctls)
{
if (control is System.Web.UI.WebControls.Label)
{
System.Web.UI.WebControls.Label lbl = (System.Web.UI.WebControls.Label)control;
lbl.Text= "";
}
if(control.Controls.Count>0)
{
ClearAllLabel(control.Controls);
}
}
}
//先自定义一个清空的方法
Public Void ClearAllLables(ControlCollection MyControlCollections)
{
foreach(System.Web.UI.Control MyControls in MyControllections)
{
if(MyControls.HasControls())
{
ClearAllLables(MyControls.Controls);
}
else
{
if(MyControls is System.Web.UI.WebControls.Lable)
{
((Lable)MyControls).Text=String.Empty;
}
}
}
}
//再调用这个方法就行了
protected void btSearch_Click(object sender, EventArgs e)
{
ClearAllLables(this.Controls);
}
if (ctrl.GetType()==typeof(Label))
{
((Label)ctrl).Text = "";
}
//这个不是已经递归了吗?