C# 如何使asp下拉列表项不可选择

C# 如何使asp下拉列表项不可选择,c#,asp.net,dropdown,C#,Asp.net,Dropdown,我编写了以下代码来显示下拉列表: <asp:DropDownList AutoPostBack="True" ID="ddlCities" runat="server" class="form-control input-sm" placeholder="" TabIndex="5"> <asp:ListItem>Select City</asp:ListItem> <asp:ListItem value="3">Ahm

我编写了以下代码来显示下拉列表:

<asp:DropDownList AutoPostBack="True" ID="ddlCities" runat="server" class="form-control input-sm" placeholder="" TabIndex="5">
       <asp:ListItem>Select City</asp:ListItem>
       <asp:ListItem value="3">Ahmedabad (All) ---------------</asp:ListItem>
       <asp:ListItem value="3_3004">&nbsp;&nbsp;&nbsp;&nbsp;Ahmedabad East</asp:ListItem>
       <asp:ListItem value="3_3005">&nbsp;&nbsp;&nbsp;&nbsp;Ahmedabad West</asp:ListItem>
       <asp:ListItem value="3_3006">&nbsp;&nbsp;&nbsp;&nbsp;Ahmedabad-Bopal and Surroundings</asp:ListItem>
       <asp:ListItem value="3_3007">&nbsp;&nbsp;&nbsp;&nbsp;Ahmedabad-Gandhinagar</asp:ListItem>
       <asp:ListItem value="3_3008">&nbsp;&nbsp;&nbsp;&nbsp;Ahmedabad-Sabarmati and Surroundings</asp:ListItem>
       <asp:ListItem value="3_3009">&nbsp;&nbsp;&nbsp;&nbsp;Ahmedabad-SG Highway and Surroundings</asp:ListItem>
</asp:DropDownList>

它不允许光标,但用户仍然可以选择此项目,是否有其他方法使此特定项目不可选择???

我想您正在寻找类似的内容。请看看它是否能帮助你

[更新]
只是回顾了你的帖子,明白你不能使用OPTGROUP。我可以知道原因吗?因为您的需求需要此选项。

即使您说禁用的属性隐藏元素,您还是错了。 禁用的属性正是您应该使用的:

    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem Value="1">First</asp:ListItem>
        <asp:ListItem Value="2" disabled="disabled">Second</asp:ListItem>
        <asp:ListItem Value="3">First</asp:ListItem>
    </asp:DropDownList>

可能重复@AzarShaikh链接中所述的解决方案无效,它将隐藏项目请不要发布仅链接答案。如果链接失效,您的答案将变得毫无用处。@Nareshpodyshetty我已经在所述链接中尝试了该解决方案,但根本不起作用。我已经提到,禁用的属性将隐藏该字段。你们所展示的结果,正是我想要的,但第二个将隐藏这一点item@ace我只是测试了一下,它并没有隐藏它。你有一些javascript或者css来隐藏它吗?Asp.net不会隐藏它,它只会禁用它。我没有任何javascript或css隐藏它,但我有ddlCities.Items[1]。Attributes.Add(“样式”,“光标:不允许”);这是一个c#代码隐藏文件,你能分享你的代码片段吗?而且你不能使用disabled=“disabled”,你可以使用enabled=“true”
ddlCities.Items[1].Attributes.Add("Style", "cursor:not-allowed");
    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem Value="1">First</asp:ListItem>
        <asp:ListItem Value="2" disabled="disabled">Second</asp:ListItem>
        <asp:ListItem Value="3">First</asp:ListItem>
    </asp:DropDownList>