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

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

 <asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
  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<string, string> Site()
{
Dictionary<string, string> site = new Dictionary<string, string>();
site.Add("Insus.NET cnblogs", "http://www.cnblogs.com/jack-Star");
site.Add("Microsoft", "http://www.microsoft.com");
site.Add("Google", "http://www.google.com");
return site;
}

禁用DropDownList的Items的更多相关文章

  1. 动态生成DropDownList 并取值

    Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Def ...

  2. GridView中DropDownList

    <asp:TemplateField HeaderText="下拉框"> <ItemTemplate> <cc1:MyDropDownList ID= ...

  3. 《ASP.NET1200例》嵌套在DataLisT控件中的其他服务器控件---DropDownList控件的数据绑定

    aspx <script type="text/javascript"> function CheckAll(Obj) { var AllObj = document. ...

  4. ASP.NET笔记之 ListView 与 DropDownList的使用(解决杨中科视频中的问题)

    1.Repeater用来显示数据.ListView用来操作数据 InsertItemTemplate和updateItemTemplate**Eval(显示数据)和Bind(双向绑定:不仅是需要展现, ...

  5. MVC扩展HtmlHelper,加入RadioButtonList、CheckBoxList、DropdownList

    代码: using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions ...

  6. datagrid与DropDownList关联使用

    最近做一个页面需要用到这个两个控件,之前虽然看过,但是没有动手实践过.突然要做这么一个页面,并用上,真的有点着急.于是乎,网上疯狂找datagrid与DropDownList 的例子,找了很多很多,看 ...

  7. 【转】ASP.NET ViewState详解

    (wyt今天学习了这篇文章,作为门外汉的我了解了很多页面控件数据加载的知识和viewstate的用法和原理.我想在日后的开发效率提升上会有很大的作用.) 转自http://www.cnblogs.co ...

  8. ASP.NET ViewState详解

    ASP.NET ViewState详解[转载] 作者:Infinities Loop 概述 ViewState是一个被误解很深的动物了.我希望通过此文章来澄清人们对ViewState的一些错误认识.为 ...

  9. ASP.NET数据绑定控件

    数据绑定控件简介 数据绑定分为:数据源 和 数据绑定控件 两部分,数据绑定控件通过数据源来获得数据,通过数据源来隔离数据提供者和数据使用者,数据源有:SqlDataSource,AccessDataS ...

随机推荐

  1. 关于javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in &lt;forEach&gt;

    今天遇到这样一个异常: 严重: Servlet.service() for servlet jsp threw exceptionjavax.servlet.jsp.JspTagException: ...

  2. 华为OJ平台——整形数组合并

    题目描述: 将两个整型数组按照升序合并,并且过滤掉重复数组元素 输入: 输入说明,按下列顺序输入: 1 输入第一个数组的个数 2 输入第一个数组的数值 3 输入第二个数组的个数 4 输入第二个数组的数 ...

  3. 华为OJ平台——首次不重复字符

    题目描述: 输入一个字符串,输出字符串中第一个没有重复的字符,若没有满足条件的字符存在,则输出“.” 思路: 这题很简单,直接逐次比较就好了,但是没有考虑到更好效率的方法,以后想到的话再加上来 imp ...

  4. MySQL版本调研

    1引言 1.1 编写目的 本文的主要目的是通过对当前项目中使用的各种版本的数据库进行比较,分析各自特性和稳定程度,最终推荐合适的版本作为今后的标准数据库. 1.2 背景 当前,部门负责管理维护的现网使 ...

  5. 創建HTTP 服務器

    var http = require('http'); var fs = require('fs'); var server = http.createServer(function(req, res ...

  6. infusion度量金字塔数据解释

    inFusion能够探测超过20中代码味道和代码缺陷,包括重复代码,破坏封装的类(如数据类或者万能类),高耦合的方法和类,以及一些设计不合理的类继承结构.当我们使用inFusion工具分析代码时,在分 ...

  7. logcat保存当前应用程序的日志并上传服务器或指定邮箱

    给大家分享一个项目中用到的日志统计并提交服务器的日志工具类.通过过得当前app的PID,采用命令行的方式实用logcat工具过滤日志.代码区: package org.and.util; import ...

  8. 显示或隐藏一个Grid

    The Rowset class contains two methods that can be used to show and hide all rows: ShowAllRows() Hide ...

  9. ADO.NET(很精彩全面)

    记录一下地址方便以后看http://www.cnblogs.com/liuhaorain/archive/2012/02/06/2340409.html

  10. 多屏判断css改写

    function replaceBodyClass(){ for(var i in map){ if(map[i](width)){ document.body.className = documen ...