Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在服务器端禁用asp.net中的DropDownList选项?_Asp.net_Drop Down Menu - Fatal编程技术网

如何在服务器端禁用asp.net中的DropDownList选项?

如何在服务器端禁用asp.net中的DropDownList选项?,asp.net,drop-down-menu,Asp.net,Drop Down Menu,我有一个dropdownlist来填写服务器端的列表,其中一些选项需要被禁用。实际上,我知道我需要添加一个disabled='disabled'属性 这是我第一次尝试 Dim avListItems = activityVersions.Select(Function(av) New With {.Text = av.Text, .Value = av.Value, .Disabled=av.HasQuota}).ToList() 但这会禁用所有选项,因为在HTML中,禁用的属性不需要值。如果

我有一个dropdownlist来填写服务器端的列表,其中一些选项需要被禁用。实际上,我知道我需要添加一个disabled='disabled'属性

这是我第一次尝试

Dim avListItems = activityVersions.Select(Function(av) New With {.Text = av.Text, .Value = av.Value, .Disabled=av.HasQuota}).ToList()
但这会禁用所有选项,因为在HTML中,禁用的属性不需要值。如果存在禁用的属性,则在任何情况下都会禁用该选项。但我需要一个解决方案,可以添加禁用属性的选项,它没有配额和其他应启用


您有什么建议吗?

无法禁用下拉列表中的单个项目。看


如果选择了无效的选项,可能会应用一些验证来通知用户,或者完全从列表中删除这些项目。

实际上可以禁用下拉列表中的项目。您需要做的是绑定列表,然后向其添加一个新属性。 下面的示例假设一个国家列表

List<Country> countryList = CountryFunctions.CreateCountryCollection();

                ddlCountryList.DataSource = countryList;
                ddlCountryList.DataTextField = "Name";
                ddlCountryList.DataValueField = "Code";
                ddlCountryList.DataBind();

                //Disable any preselected items in dropdown list
                foreach (var country in countryList)
                {
                    var disabledCountry = IsCountryDisabled(country.Code);

                    if (country.Id != 0)
                    {
                        ddlCountryList.Items.FindByValue(country.Code).Attributes.Add("disabled", "true");
                    }
                }
List countryList=CountryFunctions.CreateCountryCollection();
ddlconrylist.DataSource=countryList;
ddlcontrylist.DataTextField=“Name”;
ddlcontrylist.DataValueField=“代码”;
ddlcontrylist.DataBind();
//禁用下拉列表中的任何预选项
foreach(国家列表中的var国家)
{
var disabledCountry=IsCountryDisabled(国家/地区代码);
如果(country.Id!=0)
{
ddlCountryList.Items.FindByValue(country.Code.Attributes.Add(“disabled”、“true”);
}
}

请显示将此数据插入DDL的代码。您的权限不允许通过asp.net控件使用,但允许在HTML中使用,因此您可以在绑定事件后跳过它,请参阅我的答案。