禁用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<string, string> Site()
{
Dictionary<string, string> site = new Dictionary<string, string>();
site.Add("Insus.NET cnblogs", "http://insus.cnblogs.com");
site.Add("Microsoft", "http://www.microsoft.com");
site.Add("Google", "http://www.google.com");
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- 使用ASP.NET MVC3+EF+Jquery制作文字直播系统(四
- Web Service学习笔记(4)
- JQuery+Asp.net MVC实现用户名重名查询
- MVC3+Entity Framework 实现投票系统(二)
- 聊聊.net程序设计——浅谈使用VS2010建模拓展(下
- .NET设计模式:工厂方法模式(Factory Method)[1]
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注
- .NET简谈互操作(四:基础知识之Dispose非托管内存
- asp.net DataTable和Dataset序列化成Json格式
- .net架构的最后思考(箴言)



