asp.net 中的 DropdownList 列表项

问题描述 投票:0回答:2
c# asp.net drop-down-menu listitem
2个回答
2
投票

AppendDataBoundItems="true"
添加到 DropDownList。

<asp:DropDownList CssClass="form-control" ID="DropDownList3" runat="server"
    DataSourceID="SqlDataSource2" AppendDataBoundItems="true"
    DataTextField="ROLENAME">
    <asp:ListItem Text="Please select" Value="" Enabled="false" Selected="True"></asp:ListItem>
</asp:DropDownList>

正确的语法是

Enabled="false"
,而不是
Disabled="disabled"
。禁用=禁用是HTML代码。


0
投票

在 .cs 代码中,在 DropDownList3.DataBind() 之后插入一个如下所示的 ListItem:

this.DropDownList3.Items.Insert(0, new ListItem() { Text = "请选择", Value = string.Empty });

© www.soinside.com 2019 - 2024. All rights reserved.