在 html select 中有自定义选项和数据绑定项
Have custom options and databound items in html select
我目前正在尝试 select 在选项部分包含默认值,同时还使用 sqldatasource 对其进行数据绑定。我知道 asp:Dropdowns 有 appenddatabounditems 属性,但很好奇 select 控件是否也有类似的东西。或者是否有任何方法可以做到这一点。
<select id="ddlRFC" runat="server" datasourceid="dsRFC" DataTextField="ControlDescription" DataValueField="ControlValue" class="form-control">
<option selected>Choose...</option>
</select>
没有。查看 the source,当 HtmlSelect
控件为 data-bound:
时,任何现有项目总是被清除
/* Copyright (c) Microsoft Corporation. All rights reserved. */
// create items using the datasource
if (dataSource != null) {
...
Items.Clear();
我目前正在尝试 select 在选项部分包含默认值,同时还使用 sqldatasource 对其进行数据绑定。我知道 asp:Dropdowns 有 appenddatabounditems 属性,但很好奇 select 控件是否也有类似的东西。或者是否有任何方法可以做到这一点。
<select id="ddlRFC" runat="server" datasourceid="dsRFC" DataTextField="ControlDescription" DataValueField="ControlValue" class="form-control">
<option selected>Choose...</option>
</select>
没有。查看 the source,当 HtmlSelect
控件为 data-bound:
/* Copyright (c) Microsoft Corporation. All rights reserved. */
// create items using the datasource
if (dataSource != null) {
...
Items.Clear();