該方法:主要用于對前臺頁面的不同類型(TextBox、DropDownList、等)或全部控件進行批量操作,用于批量修改其屬性(如,Text、Enable)。
?
private void GetControlList<T>(ControlCollection controlCollection, List<T> resultCollection)where T : Control{foreach (Control control in controlCollection){ if (control is T)
resultCollection.Add((T)control);if (control.HasControls())GetControlList(control.Controls, resultCollection);}}
?
調用 ?? :主要是用來禁用 Enable 屬性,將其變為不可用。
//隱藏頁面關于資產分類的選擇控件,以及保存和提交按鈕。 List<TextBox> allTextBoxs = new List<TextBox>(); //對Textbox進行禁用GetControlList<TextBox>(Page.Controls, allTextBoxs);foreach (var childControl in allTextBoxs){childControl.Enabled = false; //call for all controls of the page }List<DropDownList> allDDLs = new List<DropDownList>(); //對dropdownlist進行禁用GetControlList<DropDownList>(Page.Controls, allDDLs);foreach (var childControl in allDDLs){childControl.Enabled = false; //call for all controls of the page}
?