zoukankan      html  css  js  c++  java
  • C#代码总结02---使用泛型来获取Asp前台页面全部控件,并进行属性修改

    该方法:主要用于对前台页面的不同类型(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
                }
  • 相关阅读:
    el-checkbox
    文件上传优化
    二叉树的建立
    二叉树的遍历算法
    两个二进制数多少个位(bit)不同
    二维矩阵置零
    search-a-2d-matrix(二维矩阵查找)
    Ubuntu16.04安装配置Eclipse 以及opencv的使用
    树莓派 自身摄像头的opencv调用
    树莓派3上安装Qt5
  • 原文地址:https://www.cnblogs.com/JesseP/p/10681141.html
Copyright © 2011-2022 走看看