禁用或启用DropDownList的Items

来源:未知 责任编辑:责任编辑 发表时间:2014-05-26 11:00 点击:
此篇算是对http://www.2cto.com/kf/201204/127918.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));

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • 浅析.NET下XML数据访问新机制
  • asp.net 面试+笔试题目第1/2页
  • C# 邮件地址是否合法的验证
  • asp.net 设置GridView的选中行的实现代码
  • C#高级编程:数据库连接[1]
  • 经典C++程序1
  • IIS 自动回收导致后台定时器失效的问题解决
  • ASP.NET&#160;GridView列表代码示例
  • Asp.net MVC源码分析--Action Filter的链式调用
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1