zoukankan      html  css  js  c++  java
  • asp.net清空某一类控件或置某一状态

    一个一个控件的清空非常麻烦,所以写了一个方法将一类的控件清空: 

    protected void btnClear_Click(object sender, EventArgs e)
        {
            foreach (Control ctl in this.Controls)
            {
                this.txtClear(ctl);
            }
        }

        private void txtClear(Control ctls)
        {
            if(ctls.HasControls())
            {
                foreach (Control ctl in ctls.Controls)
                {
                    txtClear(ctl);
                }
            }
            else
            {
                if (ctls.GetType().Name == "TextBox")
                {
                    TextBox tb = new TextBox();
                    tb = (TextBox)this.FindControl(ctls.ID);
                    tb.Text = "";
                }
                else if (ctls.GetType().Name == "DropDownList")
                {
                    DropDownList Ddlist = new DropDownList();
                    Ddlist = (DropDownList)this.FindControl(ctls.ID);
                    Ddlist .SelectedIndex = 0;
                }
            }
        }

    如果大家有其它什么好的方法,希望可以拿出来分享

    共同交流 共同学习

  • 相关阅读:
    SVG前戏—让你的View多姿多彩
    分享几个Android很强势的的开源框架
    终于,我还是下决心学Java后台了
    金9银10,分享几个重要的Android面试题
    django-多表操作2
    python基础-文件操作
    django-单表操作
    django-多表操作
    django-模板层基础2
    djano-模板层基础知识
  • 原文地址:https://www.cnblogs.com/ZHF/p/1327866.html
Copyright © 2011-2022 走看看