可以先看看效果,被禁用的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. 'UIShell.OSGi.MvcWebExtension.BundleRuntimeControllerFactory' did not return a controller for the name 'Home'.

    在使用osgi.net 框架的时候,有时会遇到这样的错误: 解决办法: 1. 检查项目文件夹下的 log 日志文件,因 osgi.net 在运行时(包括异常和操作)都会在项目的目录下生成 日志文件,并 ...

  2. 关于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: ...

  3. noip2009提高组题解

    NOIP2009题解 T1:潜伏者 题目大意:给出一段密文和破译后的明文,一个字母对应一个密文字母,要求破译一段密文,如果有矛盾或有未出现密文无法破译输出failed,否则输出明文. 思路:纯模拟题 ...

  4. IT职场求生法则(转)

    摘要:在IT职场打滚超过10年了,从小小的程序员做到常务副总.相对于其它行业,IT职场应该算比较光明的了,但也陷阱重重,本文说说我的亲身体会,希望大家能在IT职场上战无不胜! 作者:张传波 软件知识大 ...

  5. VirtualBox是什么

    VirtualBox 是一款 x86 虚拟机软件.原由德国innotek公司开发,2008年Sun收购了Innotek,而Sun于2010年被Oracle收购,2010年1月21日改 名成 Oracl ...

  6. 1.Mariadb(mysql)基本操作

    1.:安装与初始化 1)安装 yum install -y mariadb\* 2)初始化 systemctl restart mariadb systemctl enable  mariadb my ...

  7. Android中SearchView修改字体颜色

    首先获取searchView控件,比如在actionbar上获取: SearchView searchView = (SearchView) menu.findItem(R.id.action_sea ...

  8. Install SQLite

    http://www.tutorialspoint.com/sqlite/sqlite_installation.htm The SQLite is famous for its great feat ...

  9. POJ C程序设计进阶 编程题#1:计算矩阵边缘之和

    编程题#1:计算矩阵边缘元素之和 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB ...

  10. C# app.config文件配置和修改

    很多时候我们需要对系统的.config文件进度读写操作,例如:系统初始化的参数的更改.系统参数的改变都需要更新到配置文件. 首先我们有必要了解一下app.config.exe.config和vshos ...