如何使用foreach循环清除所有文本框? [英] how to use foreach loop for clear the all textboxes?

查看:121
本文介绍了如何使用foreach循环清除所有文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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循环...请告诉我.......




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.......

推荐答案

是的,你可以。自定义下面的提示/技巧。

清除表单中所有输入字段的简单方法。 [ ^ ]
Yes, you could. Customize the below Tip/Trick.
Simple and easy way to clear all the input fields in the form.[^]


访问此处...



http://social.msdn.microsoft.com/Forums/en-US/db55a8dc-5c1c-4831-af1f-a7016d42970c/foreach-loop -to-loop-all-the-text-box-in-a-form [ ^ ]







http://bytes.com/topic/c-sharp/answers/245847-how-loop-through-all-textbox-form-clear-its-values [ ^ ]
visit here...

http://social.msdn.microsoft.com/Forums/en-US/db55a8dc-5c1c-4831-af1f-a7016d42970c/foreach-loop-to-loop-all-the-text-box-in-a-form[^]

or

http://bytes.com/topic/c-sharp/answers/245847-how-loop-through-all-textbox-form-clear-its-values[^]


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";
            }
        }
    }


这篇关于如何使用foreach循环清除所有文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆