C#一次性清空TextBox或者将某一类控件置某一状态
来源:互联网 发布:中国修正主义知乎 编辑:程序博客网 时间:2024/06/07 16:09
- #region 清除
- protected void btnClear_Click(object sender, EventArgs e)
- {
- foreach (Control ctl in this.Controls)
- {
- this.txtClear(ctl);
- }
- }
- #endregion
- 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 ddl = new DropDownList();
- ddl = (DropDownList)this.FindControl(ctls.ID);
- ddl.SelectedIndex = 1;
- }
- }
- }