zoukankan      html  css  js  c++  java
  • 利用枚举为数据源,封装对应数据集合

    1、定义枚举

     /// <summary>    

     /// 枚举方法    

     /// </summary>    

     public static enum RadioMailState    

    {        
          All=0,         Men = 1,         Women = 2    

    }

    2、需要封装后的共同类

     /// <summary>    

     /// 共同类    

     /// </summary>    

     public class Common    

     {        

          /// <summary>        

          /// 获取性别的封装值        

          /// </summary>        

          /// <param name="mStrFlag">是否包含全部默认值</param>        

          /// <returns></returns>        

         public static Dictionary<RadioMailState, string> getRadioMailState(bool mStrFlag)        

         {            

                Dictionary<RadioMailState, string> dStrRadioMailState = new Dictionary<RadioMailState, string>();            

               if (mStrFlag)            

               {                

                     dStrRadioMailState.Add(RadioMailState.All, "全部");            

               }            

              dStrRadioMailState.Add(RadioMailState.Men, "男");            

              dStrRadioMailState.Add(RadioMailState.Women, "女");            

              return dStrRadioMailState;        

          }    

    }

    3、给调用的下拉控件封装值

        /// <summary>    

        /// 封装对应的按钮    

        /// </summary>    

        public class RadioControler    

       {        

           /// <summary>        

           /// 封装性别的下拉框        

           /// </summary>        

           /// <param name="listControl">下拉控件</param>        

           /// <param name="ifCheckAll">是否添加全部默认值</param>        

           public void LoadRadioMexValue(DropDownList listControl,bool ifCheckAll)        

           {            

                       Dictionary<RadioMailState, string> dStrMexStateValue = Common.getRadioMailState(ifCheckAll);        //声明取值变量                     

                       foreach (KeyValuePair<RadioMailState,string> radiovalue in dStrMexStateValue)                                 //循环取值,并赋值给下拉框            

                       {               

                                  listControl.Items.Add(new ListItem(radiovalue.Value.ToString(), radiovalue.Key.ToString()));            

                       }

                       if(listControl.Items.Count>0)                                                                                                           //如果选项不为空,那么让第一个默认选中            

                      {                

                           listControl.Items[0].Selected=true;            

                      }        

           }    

    }

  • 相关阅读:
    Unity3d通用工具类之生成文件的MD5
    Unity3d-Socket之龙一编年史network.dll分析(2)-> CNetLogger
    Unity3d-Socket之龙一编年史network.dll分析(1)
    Unity3d设计模式之单例模式
    c#中的??运算符
    java 字节流
    java File文件操作
    java 线程池和lamda表达式
    java 线程状态(通信/等待/唤醒)
    java 线程安全
  • 原文地址:https://www.cnblogs.com/BeyondWJsel/p/2342761.html
Copyright © 2011-2022 走看看