• 禁用或启用DropDownList的Items


    此篇算是对http://www.cnblogs.com/insus/archive/2012/04/17/2454620.html重构升级。

    因为网友需要不但能禁用还能可以启用DropDownList的Items。为了不想用户写太多代码。Insus.NET写了一个类别,并让它继承了System.Web.UI.WebControls命名空间下的DropDownList. 可从下图看到InsusDropDownList实例化并传入DropDownList控件,然后实例化之后的对象,就是可以使用highlight的四个方法DisableImsByText(), DisabletemsByVue() ,EnableItemsBText(), EnableItemsByValue()。

    InsusDropDownList类别:

    InsusDropDownList
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI.WebControls;

    /// <summary>
    /// Summary description for InsusDropDownList
    /// </summary>
    namespace Insus.NET
    {
        public class InsusDropDownList : DropDownList
        {
            DropDownList _DropDownList;

            public InsusDropDownList(DropDownList dropDownList)
            {
                this._DropDownList = dropDownList;
            }

            public void DisableItemsByText(string text)
            {          
                DisableItems(GetIndexByText(text));
            }

            public void EnableItemsByText(string text)
            {            
                EnableItems(GetIndexByText(text));
            }

            public void DisableItemsByValue(string value)
            {           
                DisableItems(GetIndexByValue(value));
            }

            public void EnableItemsByValue(string value)
            {            
                EnableItems(GetIndexByValue(value));
            }

            private int GetIndexByText(string text)
            {
                return this._DropDownList.Items.IndexOf(this._DropDownList.Items.FindByText(text));
            }

            private int GetIndexByValue(string value)
            {
                return this._DropDownList.Items.IndexOf(this._DropDownList.Items.FindByValue(value));
            }

            private void DisableItems(int index)
            {
                if (index > -1)
                    this._DropDownList.Items[index].Attributes.Add("disabled""disabled");
            }

            private void EnableItems(int index)
            {
                if (index > -1)
                    this._DropDownList.Items[index].Attributes.Remove("disabled");
            }
        }
    }

    演示,启用Items: 

     if (Request.QueryString["site"] != null)
            {
                InsusDropDownList obj = new InsusDropDownList(this.DropDownList1);
                obj.EnableItemsByText(Request.QueryString["site"]);
            }   
  • 相关阅读:
    flask总结02
    flask总结01
    恩智浦Freescale Cortex-A9 迅为IMX6开发板平台初体验
    [分享] IMX6嵌入式开发板linux QT挂载U盘及TF卡
    迅为4412嵌入式安卓开发板兼容3G网络|4G网络
    迅为嵌入式4412平台兼容3G/4G模块的安卓开发板
    飞思卡尔开发板-迅为IMX6开兼容单核 双核 四核Plus开发板
    物联网初学者智能家居必备迅为iTOP-4412开发板
    【分享】4412开发板POP烧写ubuntu出错,如何挂载emmc分区解决方法
    [安卓开发板]迅为IMX6 四核Android开发板
  • 原文地址:https://www.cnblogs.com/insus/p/2456828.html
Copyright © 2020-2023  润新知