public void clear()
{
lblage.Text = "";
lblclosingbirds.Text = "";
lbltypeoffeed.Text = "";
lbltypeoffeedf.Text = "";
lblstdfeed.Text = "";
lblstdfeedf.Text = "";
lblstdhd.Text = "";
lblstdhe.Text = "";
lblExpeggs.Text = "";
lblbirdsf.Text = "";
txtacteggs.Text = "";
txtactfeed.Text = "";
txtactfeedf.Text = "";
txtfemaleclosingstock50.Text = "";
txtfemaleclosingstock70.Text = "";
txtmale50kgcstock.Text = "";
txtmale70kgscstock.Text = "";
txtmort.Text = "";
txtmortf.Text = "";
txtuseeggs.Text = "";
ddlFemaleFeedtype.SelectedValue = "0";
ddlMaleFeedtype.SelectedValue = "0";
}
如何使用 foreach 循环方法替换为clear()..请告诉我..任何一个... 是否可以编写 foreach 循环...请告诉我
最佳答案
void ClearAllControlsRecursive(Control container)
{
foreach(var control As Control in container.Controls)
{
if(typeof control is TextBox)
{
((TextBox)control).Text = String.Empty;
}
if(control.HasControls())
{
ClearAllControlsRecursive(control);
}
}
}
然后像这样调用这个方法:
ClearAllControlsRecursive(yourContainer);
您还可以打开控件类型并相应地清除值。
关于asp.net - 如何使用 foreach 循环清除所有文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19154780/