如何添加初始“选择"DropDownList 的值 [英] How to add an initial "select" value to a DropDownList
本文介绍了如何添加初始“选择"DropDownList 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我使用 DropDownList:
If I use a DropDownList:
<asp:DropDownList ID="DropDownListSubContractors" runat="server"
DataTextField="Company_Name" DataValueField="id">
</asp:DropDownList>
我使用/设置什么属性允许我使用---Select---"作为下拉列表中的初始选项,而不是列表中的第一个值.
What attribute do I use/set that allows me to use '---Select---' as initial option on the drop down, instead of the first value in the list.
推荐答案
可以使用
<asp:DropDownList ID="DropDownListSubContractors" runat="server" AppendDataBoundItems="true" DataTextField="Company_Name" DataValueField="id">
<asp:ListItem Text="---Select---" Value="0" />
</asp:DropDownList>
或者你可以像这样在代码后面动态添加这个
Or you can add this dynamically at code behind like this
DropDownListSubContractors.Items.Add(new ListItem("---Select---", "0"));
这篇关于如何添加初始“选择"DropDownList 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文