Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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.......
Posted
Updated 3-Oct-13 1:59am
v2
Comments
BillWoodruff 3-Oct-13 9:22am    
Are all these TextBoxes in the same Container ? I sincerely hope I never meet a male 70kg. chicken, or a hen who weighs 50kg. ! :)

Yes, you could. Customize the below Tip/Trick.
Simple and easy way to clear all the input fields in the form.[^]
 
Share this answer
 
Comments
Renju Vinod 3-Oct-13 8:04am    
+5
C#
void CleareAllcontrolsRecursive(Control container)
    {
        foreach (var control in container.Controls)
        {
            if (control is TextBox)
            {
                ((TextBox)control).Text = string.Empty;


            }
            if (control is DropDownList)
            {
                ((DropDownList)control).SelectedValue = "0";
            }
        }
    }
 
Share this answer
 
v3
Comments
BillWoodruff 3-Oct-13 9:21am    
This code is not recursive. However it is not clear from your original question whether you need a recursive solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900