gpt4 book ai didi

asp.net - 如何使用 foreach 循环清除所有文本框?

转载 作者:行者123 更新时间:2023-12-02 10:40:36 28 4
gpt4 key购买 nike

 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com