A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

  1. #region 遍历界面上所有控件进行属性设置
  2. /// <summary>
  3. /// 遍历界面上所有控件进行属性设置
  4. /// </summary>
  5. /// <param name="page"></param>
  6. /// <param name="type">
  7. ///isClear是添加时候,清空数据信息,如果该控件为只读属性则不需要清除文本数据信息,
  8. ///如果type参数为空数值则默认为查看状态,控件都全部禁用掉
  9. /// </param>
  10. public static void initControl(Control page, string type)
  11. {
  12.     int nPageControls = page.Controls.Count;  //获取页面的控件
  13.     for (int i = 0; i < nPageControls; i++)
  14.     {
  15.         foreach (Control control in page.Controls[i].Controls)
  16.         {
  17.             {
  18.                 //文本框控件
  19.                 if (control is TextBox)
  20.                 {
  21.                     TextBox txtBox = (TextBox)control;
  22.                     //如果是点击重置,需要判断是否为只读属性,如果是则不进行清除数据
  23.                     if (type == "isClear" && txtBox.Enabled != false)
  24.                         txtBox.Text = "";
  25.                     else
  26.                         txtBox.Enabled = false;
  27.                 }
  28.                 //下拉框控件
  29.                 if (control is DropDownList)
  30.                 {
  31.                     DropDownList ddlList = (DropDownList)control;
  32.                     if (type == "isClear" && ddlList.Enabled != false)
  33.                         ddlList.SelectedIndex = -1;
  34.                     else
  35.                         ddlList.Enabled = false;
  36.                 }
  37.                 //复选框控件
  38.                 if (control is CheckBox)
  39.                 {
  40.                     CheckBox chkBox = (CheckBox)control;
  41.                     if (type == "isClear" && chkBox.Enabled != false)
  42.                         chkBox.Checked = false;
  43.                     else
  44.                         chkBox.Enabled = false;
  45.                 }
  46.                 //点击按钮
  47.                 if (control is Button)
  48.                 {
  49.                     Button btn = (Button)control;
  50.                     if (type == "isClear" && btn.Enabled != false)
  51.                         btn.Enabled = true;
  52.                     else
  53.                         btn.Enabled = false;
  54.                 }
  55.                 if (control is RadioButtonList)
  56.                 {
  57.                     RadioButtonList radioList = (RadioButtonList)control;
  58.                     if (type == "isClear" && radioList.Enabled != false)
  59.                         radioList.SelectedIndex = -1;
  60.                     else
  61.                         radioList.Enabled = false;
  62.                 }
  63.             }
  64.         }
  65.     }

  66. }
  67. #endregion
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马