zoukankan      html  css  js  c++  java
  • 禁用DropDownList的Items

    可以先看看效果,被禁用的DropDownList的Items已经无法选取与颜色也变为灰色。

    刚开始,DropDownList没有接收从网址传来的参数时,它每一个Item都是可以选取的,一旦接收了值。所对应的DropDownList的item将无法选取而达到禁用。

    xxx.aspx:

     <asp:DropDownList ID="DropDownList1" runat="server">
            </asp:DropDownList>

    xxx.aspx.cs: 

    View Code
     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Data_Binding();
            }

            if (Request.QueryString["site"] != null)
            {
                foreach (ListItem li in DropDownList1.Items)
                {
                    if (li.Text == Request.QueryString["site"].ToString())
                    {
                        li.Attributes.Add("disabled""disabled");
                    }
                }
            }

        }

        private void Data_Binding()
        {
            this.DropDownList1.DataSource = Site();
            this.DropDownList1.DataTextField = "key";
            this.DropDownList1.DataValueField = "value";
            this.DropDownList1.DataBind();
        }

        private Dictionary<stringstring> Site()
        {
            Dictionary<stringstring> site = new Dictionary<stringstring>();
            site.Add("Insus.NET cnblogs""http://insus.cnblogs.com");
            site.Add("Microsoft""http://www.microsoft.com");
            site.Add("Google""http://www.google.com");
            return site;
        }
  • 相关阅读:
    Corlpack 0.5.1 发布,Ada 工具包
    HTML5状况及发展形势报告发布
    c++gtkutils 2.0.14 发布,轻量级的 C++ 类库
    Resin 4.0.34 发布,Java应用服务器
    IntelliJ IDEA 12.0.3 更新版发布
    StoryText 3.9 发布,图形界面测试工具
    UberStudent 2.0 "Lightweight" 发布
    中国移动集中化BI探索:数据仓库与Hadoop混搭
    MariaDB 10.0 和 MySQL 5.6 有何不同
    Java 转原生平台代码 RoboVM
  • 原文地址:https://www.cnblogs.com/insus/p/2454620.html
Copyright © 2011-2022 走看看