下拉框绑定数据后添加“请选择”项

通常我们将数据从数据库读取出来绑定到下拉框中,希望在下拉框中默认显示为“请选择”,之前一直是在后台添加,这种方法不但麻烦,而且效率低。

下面为前台添加:

<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="ddlNation" runat="server" AppendDataBoundItems="true">
            <asp:ListItem Value="0">请选择</asp:ListItem>
        </asp:DropDownList>
    </div>
    </form>
</body>

AppendDataBoundItems="true" 设置允许“向后追加”,所以从数据库中获得的数据都绑定在“请选择”之后

原文地址:https://www.cnblogs.com/qianxingdewoniu/p/2757851.html