c# - ASP.Net Dropdownlist ListItem (Enabled=false) 未显示在页面中

标签 c# asp.net

我在 aspx 中有一个名为 ddlServicedropdownlist

我想从后面添加列表项。

当我添加时,我会按照标题和下面的项目的顺序创建它们,比如..

Title1
Item1
Item2
Title2
Item1
Item2

标题应该不能点击。只有项目应该能够点击。

ListItem tempServicesItem = new ListItem();
tempServicesItem.Text = tempTitle;
tempServicesItem.Value = tempTitle;
tempServicesItem.Enabled = false;     
ddlServices.Items.Add(tempServicesItem);
tempServicesItem = new ListItem();
tempServicesItem.Text = tempItem;
tempServicesItem.Value = tempItem;                                                        
ddlServices.Items.Add(tempServicesItem);

我遇到的问题是带有 (Enabled=false) 的 ListItems 没有出现在 aspx 中。

当我将其更改为 (Enabled=true) 时,它出现了。

我一定是漏掉了什么。谁能指出来?

谢谢。

最佳答案

我相信这就是您要找的。 (未测试)

tempServicesItem.Attributes.Add("disabled", "disabled");

关于c# - ASP.Net Dropdownlist ListItem (Enabled=false) 未显示在页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9170286/

相关文章:

c# - 如何在没有边框的窗体周围添加阴影?

c# - 运算符 '==' 不能应用于类型 'int' 和 'System.Linq.iQueryable<int>' 的操作数

c# - 如何模拟 OwinContext.Request.Query

javascript - Javascript 可以禁用 UserControl 中的 ASP.Net 控件吗?

ASP.Net Core 2 ServiceProviderOptions.ValidateScopes 属性

html - 将 Bootstrap 元素添加到 asp 文本框

c# - 想隐藏cmd提示画面

c# - MONO 的多门户 CMS

asp.net - 复制 。 .用于 ASP.NET 的 Dockerfile 中的命令

c# - ASP.NET 中的自动填充文本框取决于在另一个文本框中键入的文本