在DropDown中添加"选择"项

Man*_*tal 2 asp.net dynamic-data

我正在使用ASP.NET动态数据.在Insert.aspx页面中,我有几个下拉列表要选择.Dropdown表示的字段是数据库中的必填字段.因此下拉列表不会在下拉列表中显示"选择"作为默认选项.我想在下拉列表中显示的数据库的其他记录顶部添加"选择"选项.请注意,该字段不是必填字段,因此默认情况下,动态数据不会显示"选择"选项.我怎么能做到这一点?

Can*_*var 9

使用Insert方法绑定下拉列表后添加"select"项:

myDropDownList.DataBind();
// To make it the first element at the list, use 0 index : 
myDropDownList.Items.Insert(0, new ListItem("Select", string.Empty));
Run Code Online (Sandbox Code Playgroud)