批处理按钮

   题目:根据数组S_Roles中的值,来批量设置Button的Enabled属性

  方法一:

      foreach (string s in S_Roles)
            {
                switch (s)
                {
                    case "1":
                        btn_1.Enabled = true;
                        break;
                    case "2":
                        btn_2.Enabled = true;
                        break;
                    case "3":
                        btn_3.Enabled = true;
                        break;
                    case "4":
                        btn_4.Enabled = true;
                        break;
                    case "5":
                        btn_5.Enabled = true;
                        break;
                    case "6":
                        btn_6.Enabled = true;
                        break;
                    case "7":
                        btn_7.Enabled = true;
                        break;
                    default:
                        break;

                }
            }

方法二:string b = string.Empty;   //构建字符串
            foreach (string s in S_Roles)
            {
                b = "btn_" + s.ToString();
                Button buttons = (Button)this.FindControl(b);
                buttons.Enabled = true;
            }

个人比较喜欢第二中方法。

posted @ 2012-06-12 17:03  jsping68  阅读(281)  评论(0编辑  收藏  举报