首页 > Windows开发 > 详细

C# DropDownList 绑定枚举类

时间:2017-09-09 14:17:13      阅读:293      评论:0      收藏:0      [点我收藏+]

第一种

 

  DropDownList_Franchiser_Type.DataSource = ListTypeForEnum();
  DropDownList_Franchiser_Type.DataValueField = "value";
  DropDownList_Franchiser_Type.DataTextField = "text";
  DropDownList_Franchiser_Type.DataBind() 

  //转换枚举类
  public static IList ListTypeForEnum()
        {
            ArrayList list = new ArrayList();
            foreach (int i in Enum.GetValues(typeof(FranchiserEnum)))
            {
                ListItem listitem = new ListItem(Enum.GetName(typeof(FranchiserEnum), i), i.ToString());
                list.Add(listitem);
            }
            return list;
        }

//第二种

  DropDownList_Franchiser_Type.DataSource = System.Enum.GetNames(typeof(FranchiserEnum));
                DropDownList_Franchiser_Type.DataBind();
                ListItem li = new ListItem("--请选择--", "");
                this.DropDownList_Franchiser_Type.Items.Insert(0, li);


//枚举


    /// <summary>
    /// 经销商类别
    /// </summary>
    public enum FranchiserEnum 
    {
        [Display(Name = "")]
        无 = 0,
        [Display(Name = "签约经销商(B类)")]
        签约经销商 = 1, 
        [Display(Name = "非签约经销商(C类)")]
        非签约经销商 = 2, 
        [Display(Name = "个人")]
        个人 = 3, 
        [Display(Name = "自有仓库")]
        自有仓库 = 4,
        [Display(Name = "其他")]
        其他 = 5,

    }

 

C# DropDownList 绑定枚举类

原文:http://www.cnblogs.com/szlblog/p/7498094.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!