• 利用发射 下拉列表绑定枚举


      public static DataTable GetDataTable(Type enumType)
            {
               // NameValueCollection nvc = new NameValueCollection();
                Type typeDescription = typeof(DescriptionAttribute);
                System.Reflection.FieldInfo[] fields = enumType.GetFields();
                string strText = string.Empty;
                string strValue = string.Empty;
                DataTable table = new DataTable();
                table.Columns.Add("Name", Type.GetType("System.String"));
                table.Columns.Add("Value", Type.GetType("System.Int32"));

                foreach(FieldInfo field in fields)
                {
                    if(field.FieldType.IsEnum == true)
                    {
                        DataRow row = table.NewRow();

                        strValue = ((int)enumType.InvokeMember(field.Name,BindingFlags.GetField,null,null,   null)).ToString();

                        row[1] = strValue;
                       object[] arr = field.GetCustomAttributes(typeDescription,true);
                      if (arr.Length> 0)
                        {
                            DescriptionAttribute aa = (DescriptionAttribute)arr[0];
                         
                            row[0] = aa.Description;
                        }
                        else
                        {
                            row[0] = field.Name;
                        }
                        //nvc.Add(strText,strValue);
                        table.Rows.Add(row);

                    }
                }
                return table;
             }

  • 相关阅读:
    鼠标移入和鼠标移出的提示,和样式的转换
    HTML5——新特性,拖放
    关于订阅发布模式
    titanium环境配置
    Matlab与C混编的介绍
    一个相对健壮的node 静态http服务器
    阻赛非阻塞同步异步
    最近在做的事以及一些安排
    说一说js中__proto__和prototype以及原型继承的那些事
    PHP写的爬虫,爬指定网站页面上的各种图片
  • 原文地址:https://www.cnblogs.com/youngerliu/p/2569573.html
Copyright © 2020-2023  润新知