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";
}
how to use foreach loop method for replace with clear()..please tell me.. any one... is it possible to write foreach loop...please tell me
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);
}
}
}
then call this method like this:
ClearAllControlsRecursive(yourContainer);
You can also switch on the control type and clear the values accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With