之前 写的一个 有点麻烦,现在写一个 通用的:
调用的时候直接:Clear(this); 即可!
public void Clear(System.Web.UI.Control topctrl) { foreach (System.Web.UI.Control ctrl in topctrl.Controls) { if (ctrl.GetType().ToString() == "System.Web.UI.WebControls.TextBox") { ((System.Web.UI.WebControls.TextBox)ctrl).Text = "";//清空TextBox } else if (ctrl.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlInputText") { ((System.Web.UI.HtmlControls.HtmlInputText)ctrl).Value = "";//把InputText设为空 } else if (ctrl.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlTextArea") { ((System.Web.UI.HtmlControls.HtmlTextArea)ctrl).Value = "";//把HtmlTextArea设为空 } else if (ctrl.GetType().ToString() == "System.Web.UI.WebControls.CheckBoxList") { CheckBoxList list = (System.Web.UI.WebControls.CheckBoxList)ctrl; for (int i = 0; i < list.Items.Count; i++) { list.Items[i].Selected = false; } } //....其它的可自行扩展 if (ctrl.HasControls()) Clear(ctrl); } }