可以先看看效果,被禁用的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://insus.cnblogs.com");
site.Add("Microsoft", "http://www.microsoft.com");
site.Add("Google", "http://www.google.com");
return site;
}
分享到:
相关推荐
this.DropDownList2.Items.Clear(); this.DropDownList2.Items.Add("南阳市"); this.DropDownList2.Items.Add("信阳市"); this.DropDownList2.Items.Add("郑州市"); this.DropDownList2.Items.Add("周口市"); ...
DropDownList
DropDownList无刷新三级联动 caomianpublic void getDdlInfo(DropDownList province,DropDownList city,DropDownList town,Page myPage) { //初始化省 string sql="select 序号,省名 from 省表"; SqlCommand ...
dropdownlist下拉框实现多选
C#编程 WinForm窗体开发 DropDownList(源码)C#编程 WinForm窗体开发 DropDownList(源码)C#编程 WinForm窗体开发 DropDownList(源码)C#编程 WinForm窗体开发 DropDownList(源码)C#编程 WinForm窗体开发 DropDownList...
方法一: 实现代码 代码如下: ... DropDownList1.SelectedIndex = ddl.Items.IndexOf(DropDownList1.Items.FindByValue(“i”)); //i要自己去获取你要显示的项的id。 方法二:我贴上部分代码 获取数据后 根据该
调用方法:DropDownList.bind(selectId).例如: --------------------------------- DropDownList2: <option selected="selected" value="35">gdfgfdgjjjjjjjjjjjj └All Categories ...
DropDownList分组扩展DropDownList分组扩展DropDownList分组扩展DropDownList分组扩展
jquery异步绑定dropdownlist
DropDownList 3级联动,非常实用
三层结构 DropDownList无极分类 用泛型 DropDownList无极分类 用泛型 DropDownList无极分类 用泛型 DropDownList无极分类 用泛型
级联菜单DropDownList 级联菜单DropDownList 级联菜单DropDownList 级联菜单DropDownList 级联菜单DropDownList 级联菜单DropDownList 级联菜单DropDownList
简单使用DropDownList实现级连,手动添加下拉列表的值
重写 DropDownList 添加optgroup以及为ListItem 加式样(例如 背景色,前景色等)
asp.net Dropdownlist结合CheckBoxList多选下拉框
一共需要另外的两个文件,一个Combox.js和一个Combox.css文件。...//DropDownList1为DropDownList控件的Id,300为线框显示的宽度,280为箭头显示的宽度 new Combox("DropDownList1",300,280); </script>
在.net 中点击清空按钮可以清空dropdownlist里面值得方法
DropdownList绑定数据的方法
DropDownList与TextBox互动
重写DropDownList控件 可以输入字符