如何添加一个初始"选取[值一个DropDownList [英] How to add an initial "select" value to a DropDownList

查看:129
本文介绍了如何添加一个初始"选取[值一个DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我用一个DropDownList:

If I use a DropDownList:

 <asp:DropDownList ID="DropDownListSubContractors" runat="server" 
     DataTextField="Company_Name" DataValueField="id">
 </asp:DropDownList>

什么属性我用/集,允许我用'---选择---作为下拉选项初期,而不是​​在列表中的第一个值。

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>

或者你也可以动态地code后面添加此类似这样

Or you can add this dynamically at code behind like this

DropDownListSubContractors.Items.Add(new ListItem("---Select---", "0"));

这篇关于如何添加一个初始&QUOT;选取[值一个DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆