I have a DropDownList bound to a SqlDataSource as follows:
<asp:DropDownList ID="ddlist" AppendDataBoundItems="True" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="value" AutoPostBack="True" runat="server">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:myConnectionString %>" SelectCommand="SELECT [name], [value] FROM [myTable]" runat="server"></asp:SqlDataSource>
I would like to bind a third database column to another attribute (not value), say database table column DefaultBit
to ListItem attribute data-default
so that the DropDownList renders as
<select>
<option></option>
<option value="1" data-default="1">Line 1</option>
<option value="2" data-default="0">Line 2</option>
</select>
I assume I need to do this programmatically in the code-behind file, but it's not clear to me if I would still bind a SqlDataSource to the DropDownList or if I should open a connection and iterate through the results using SqlReader and update the DropDownList "manually" or some other more elegant solution.