zoukankan      html  css  js  c++  java
  • DropDownList 绑定 枚举 Enum

    public static List<ListItem> GetEnumList(Type enumType, bool allAllOption)
        
    {
            
    if (enumType.IsEnum == false)
            
    {
                
    return null;
            }

            List
    <ListItem> list = new List<ListItem>();
            
    if (allAllOption == true)
            
    {
                list.Add(
    new ListItem("--全部--"""));
            }


            Type typeDescription 
    = typeof(DescriptionAttribute);
            System.Reflection.FieldInfo[] fields 
    = enumType.GetFields();
            
    string strText = string.Empty;
            
    string strValue = string.Empty;
            
    foreach (FieldInfo field in fields)
            
    {
                
    if (field.IsSpecialName) continue;
                strValue 
    = field.GetRawConstantValue().ToString();
                
    object[] arr = field.GetCustomAttributes(typeDescription, true);
                
    if (arr.Length > 0)
                
    {
                    strText 
    = (arr[0as DescriptionAttribute).Description;
                }

                
    else
                
    {
                    strText 
    = field.Name;
                }


                list.Add(
    new ListItem(strText, strValue));
            }


            
    return list;
        }

        /**//// </summary>
        
    /// 派驻申请的状态
        
    /// </summary>

        public enum AccreditStatus
        
    {
            
    /**//// <summary>
            
    /// 已经结束
            
    /// </summary>

            [Description("结束")]
            Pass 
    = 2,

            
    /**//// <summary>
            
    /// 新建
            
    /// </summary>

           [Description("新建")]
            New 
    = 0,

            
    /**//// <summary>
            
    /// 在审批中
            
    /// </summary>

            [Description("审批中")]
            Running 
    = 1,

            
    /**//// <summary>
            
    /// 被拒绝
            
    /// </summary>

            [Description("被拒绝")]
            Refuse 
    = -1
        }

                this.ddlState.DataSource = Global.GetEnumList(typeof(AccreditStatus), true);
                this.ddlState.DataTextField = "Text";
                this.ddlState.DataValueField = "Value";
                this.ddlState.DataBind();

  • 相关阅读:
    atcoder 2017Code festival C ——D题 Yet Another Palindrome Partitioning(思维+dp)
    51nod 1089最长回文子串V2 (manacher)
    Codeforces Round #362(Div1) D Legen...(AC自动机+矩阵快速幂)
    51nod 1532 带可选字符的多字符串匹配(位运算)
    51nod 1317 相似字符串对(容斥原理+思维)
    51nod 1526 分配笔名(字典树+贪心)
    51nod 1292 字符串中的最大值V2(后缀自动机)
    51nod 1277字符串中的最大值(拓展kmp)
    SPOJ:[DIVCNT3]Counting Divisors
    单纯形法模板
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090533.html
Copyright © 2011-2022 走看看