Empty Option in DropDownList Bound to LinqDataSource
This has been driving me a little crazy. Sure if it was a completely code side binding I could insert the empty row into the datasource myself but I’m doing lots of work in ListViews of late so that option is totally out. I ended up finding the answer on StackOverflow.
<asp:DropDownList ID="ddlEditEmployee" AppendDataBoundItems="true" runat="server" DataTextField="Value" DataValueField="ID" SelectedValue='<%# Bind("EmployeeID") %>' DataSourceID="LinqDataSource2"> <asp:ListItem Value="-1"> None </asp:ListItem> </asp:DropDownList>
The AppendDataBoundItems bit is important too otherwise sneaking that default on in there is for nothing. Enjoy.