禁用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");
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- 教你如何来恢复一个丢失的数据文件
- winform下通过webclient使用非流方式上传(post)数据和
- asp.net js模拟Button点击事件
- 谈.Net委托与线程——创建无阻塞的异步调用(一
- MVC中一个表单实现多个提交按钮(一个action搞定
- Pro ASP.NET MVC 3 Framework学习笔记之九
- asp.net 六大内置对象(2)
- ASP.NET数据格式的Format--DataFormatString
- 微软ASP.NET站点部署指南(11):部署SQL Server数据
- Asp.net MVC源码分析--Model Validation(Client端)实现(2)