zoukankan      html  css  js  c++  java
  • 利用发射 下拉列表绑定枚举

      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;
             }

  • 相关阅读:
    MFC编程入门之二十八(常用控件:列表视图控件List Control上)
    Discuz X1.5 利用添加好友处存储xss进行蠕虫worm扩散
    全民wifi钓鱼来临----agnes安卓wifi钓鱼神器介绍
    自改xss小平台上线
    谈网页游戏外挂之用python模拟游戏(热血三国2)登陆
    thinkpad t440p 解决无线网卡驱动
    编写php拓展实例--slime项目(用户登录会话类)
    用Tupper自我指涉公式造图
    一首歌
    rtx信息泄漏利结合弱口令导致被批量社工思路
  • 原文地址:https://www.cnblogs.com/youngerliu/p/2569573.html
Copyright © 2011-2022 走看看