决定一个人富有的三个条件,一是出身,二是运气,三是努力
If you can dream it,you can do it! Nothing Impossible~

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

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

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

共同交流 共同学习

posted on 2008-11-06 10:26  ZEKELOVE  阅读(410)  评论(0编辑  收藏  举报