禁用下拉列表项 [英] disable dropdown list item

查看:133
本文介绍了禁用下拉列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要在asp.net中创建包含项目的下拉列表,该列表显示所有项目,但其中一些禁用选择.


例如

Hi to all,

i need to create drop-down list in asp.net with items, which display all items but some of them disable for select.


e.g

public void fillDrp()
   {
       drp1.Items.Clear();
       drp1.Items.Add(new ListItem("a", "1", true));
       drp1.Items.Add(new ListItem("b", "2", true));
       drp1.Items.Add(new ListItem("c", "3", false));
       drp1.Items.Add(new ListItem("d", "4", true));
   }



此代码隐藏了项目"c",而我需要在列表中显示该项目,但禁用选择.

在此先感谢... :)
--Amit



this code is hiding the item "c", while i need to show this item in to list but make disable for selection.

Thanks in advance... :)
--Amit

推荐答案

朋友

对于这种类型,我们应该编写像
这样的javascript

函数change()
{
var dd = document.getElementById(& lt;%= DropDownList1.ClientID%& gt ;;");
var value = dd.options [dd.selectedIndex] .value;
if(值!=您的禁用索引)
{
做你想做的事
}
}
hi friend

for this type we should write a javascript like


function change()
{
var dd=document.getElementById ("<%=DropDownList1.ClientID %>;'');
var value=dd.options[dd.selectedIndex].value;
if(value!=your disabled index)
{
do what you want
}
}


我可以肯定,使用HTML无法实现您想要的东西,这意味着在ASP.NET中是不可能的.您能做的最好的事情就是编写JavaScript,以检测何时选择了黑名单中的某项并将其取消选中.
I am pretty much certain that what you want is impossible using HTML, which means it''s impossible in ASP.NET. The best you can do, is to write javascript that detects when something in your blacklist is selected, and unselected it.


这篇关于禁用下拉列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆