代码之家  ›  专栏  ›  技术社区  ›  Chuck Le Butt

如何禁用列表项?

  •  6
  • Chuck Le Butt  · 技术社区  · 14 年前

    我有一个 DropDownList 在具有 ListItem Enable="False" . 我也不想让整个 ,只有一个特定的 列表项 . 我说的是写在 HTML格式 disabled="disabled" ,就像这样:

    <option disabled="disabled" value="-1">Disabled Option</option>
    

    2 回复  |  直到 6 年前
        1
  •  7
  •   Arnold Zokas    14 年前

    你试过添加 disabled="disabled"

    <asp:DropDownList runat="server" ID="id">
        <asp:ListItem Text="Test" Value="value" disabled="disabled" />
    </asp:DropDownList>
    

    请记住,浏览器兼容性各不相同: http://www.lattimore.id.au/2005/06/18/disable-options-in-a-select-dropdown-element/

        2
  •  7
  •   Simon Martin    13 年前

    你可以试着设置 attribute 通过代码隐藏,您可以通过编程方式决定要设置的值。

    所以在你的例子中,你会这样做:

    var listItem = DropDownList.Items.FindByText("Your Item Text");
    listItem.Attributes["disabled"]="disabled";