zoukankan      html  css  js  c++  java
  • 项目中用到的小技巧

    1 显示枚举的值:<%# (CN80s.DDPM.Model.Enum.EnumBidCardStatus)(int)Eval("PerpaidCard_Status")%>

    2 为下拉框绑定枚举:  

                GetEnumList(ddlBids); 

           void GetEnumList(DropDownList ddl)

            {

                foreach (EnumBidCardType s in System.Enum.GetValues(typeof(EnumBidCardType)))

                {

                    ddl.Items.Add(new ListItem(s.ToString(), ((int)s).ToString()));

                }

            } 

            this.ddlBids.DataSource = GetEnumList(typeof(EnumBidCardType), true);

                    this.ddlBids.DataTextField = "Text";

                    this.ddlBids.DataValueField = "Value";

                    this.ddlBids.DataBind(); 

            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[0] as DescriptionAttribute).Description;

                    }

                    else

                    {

                        strText = field.Name;

                    }


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

                }


                return list;

            } 

  • 相关阅读:
    C#编写功能让你的系统导入注册表文件时不提示
    登陆框提示历史记录
    C# 操作系统防火墙
    C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装 (续集Tomcat 配置)
    C# 修饰符你记住了吗?
    C# 实现设置系统环境变量设置
    showModalDialog使用例子,父窗口向子窗口传递值
    C#后台无刷新页面弹出alert方法
    VS2008 无法启动调试.未安装Silverlight托管调试包 .
    在GridView中使用FindControl .
  • 原文地址:https://www.cnblogs.com/langlang/p/1682364.html
Copyright © 2011-2022 走看看