On my page I have a DropDownList which I populate with database values from an SqlDataSource (see code below).
How can I add my own text or a blank line before the values?
<asp:DropDownList ID="drpClient" runat="server" Width="200px"      AutoPostBack="True" DataSourceID="dsClients" DataTextField="name"          DataValueField="client_id"> </asp:DropDownList> <asp:SqlDataSource ID="dsClients" runat="server"      ConnectionString="my_connection_string"      ProviderName="System.Data.SqlClient"      SelectCommand="SELECT [client_id], [name] FROM [clients]"> </asp:SqlDataSource>   Thanks.
P.S. Do you recommend using a SqlDataSource or is it better to populate another way?
You can simply add a ListItem inside the DropDownList Markup. All the values from the DataSource will be appended after that.
<asp:DropDownList ID="drpClient" runat="server" Width="200px"            AutoPostBack="True" DataSourceID="dsClients" DataTextField="name"            DataValueField="client_id" AppendDataBoundItems="true">    <asp:ListItem>-- pick one --</asp:ListItem> </asp:DropDownList> 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With