我有一个 DropDownList,它是数据绑定(bind)到 SQL Server 数据源的。实际上,数据源中的第一个条目是默认选择的第一个条目。为了选择此条目(并调用 DropDownList_SelectedIndexChange() 函数),我必须选择第二个选项,然后再次选择第一个选项。
有没有办法将无效项目作为第一个项目输入到 DropDownList 中,有点像“默认值”?
最佳答案
设置AppendDataBoundItems在下拉列表中设置为 true,然后将默认项添加到列表中
<asp:DropDownList ID="ddlOne" runat="server" AppendDataBoundItems="True"
DataSourceID="" DataTextField="" DataValueField="">
<asp:ListItem Value="">Please Select</asp:ListItem>
</asp:DropDownList>
这将导致您所有的数据绑定(bind)值都被添加到您在上面的标记中指定的值之后的下拉列表中
关于c# - 为 DropDownList 的第一个条目添加一个空白值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17795009/