I am currently trying to have a select contain a default value in the options section, while also databinding it using a sqldatasource. I know that asp:Dropdowns have the appenddatabounditems attribute, but was curious if select controls also have something similar. Or if there is any way to do this at all.
<select id="ddlRFC" runat="server" datasourceid="dsRFC" DataTextField="ControlDescription" DataValueField="ControlValue" >
<option selected>Choose...</option>
</select>
CodePudding user response:
It doesn't. Looking at the source, any existing items are always cleared when the HtmlSelect
control is data-bound:
/* Copyright (c) Microsoft Corporation. All rights reserved. */
// create items using the datasource
if (dataSource != null) {
...
Items.Clear();