Dropdownlist统一配置(从xml或枚举读取数据),应用文件依赖缓存.

1.从xml中读取配置信息 

/// <summary>
        /// 重新绑定下拉配
        /// </summary>
        /// <param name="drp">要绑定的下拉框</param>
        /// <param name="nodeName">xml节点名称</param>
        /// <param name="exceptLineName">不显示的项,支持多项,以","隔开</param>
        /// <param name="selectedVale">要选中的项</param>
        public static void BindDrpLine(DropDownList drp, string nodeName, string exceptLineName,string selectedValue)
        {
            drp.Items.Clear();
            drp.Items.Add(new ListItem("请选择...", "0"));
            string drpLineCahe = (string)HttpContext.Current.Cache[nodeName];
            if (drpLineCahe == null)
            {
                string filename = HttpContext.Current.Server.MapPath("~/DrpLine.xml");
                XmlDocument xmlDrpLine = new XmlDocument();
                xmlDrpLine.Load(filename);
                XmlNode node = xmlDrpLine.SelectSingleNode(nodeName);
                string strDrpLine = node.InnerText;
                HttpContext.Current.Cache.Insert(nodeName, strDrpLine, new System.Web.Caching.CacheDependency(filename));
                drpLineCahe = (string)HttpContext.Current.Cache[nodeName];
            }
            string[] arrDrpLine = drpLineCahe.Split(';');
            string[] drpLineVale;
            foreach (string arr in arrDrpLine)
            {
                drpLineVale = arr.Split(':');
                if (drpLineVale.Length == 2)
                {
                    if (!exceptLineName.Contains(drpLineVale[1].Trim()))
                    {
                        drp.Items.Add(new ListItem(drpLineVale[1].Trim(), drpLineVale[0].Trim()));
                    }
                }
            }
            if (selectedValue.Length > 0)
            {
                drp.SelectedValue = selectedValue;
            }
        }

2.从枚举类型读取配置信息.

    private void BindDropDown(DropDownList drp, string exceptProductName)
    {
        drp.Items.Clear();
        foreach (int i in Enum.GetValues(typeof(ProductLine)))
        {
            string strEnumName = Enum.GetName(typeof(ProductLine), i).ToString();
            if (!exceptProductName.Contains(strEnumName))
            {
                drp.Items.Add(new ListItem(strEnumName, i.ToString()));
            }
        }
    }
    public  enum ProductLine
    {
        安防 = 1, //是否显示边框 
        升腾 = 2, //是否显示标题 
        数字 = 3 //是否显示工具箱 
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值