Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net dropdownlist - add blank line before db values

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?

like image 934
thegunner Avatar asked Jun 11 '09 21:06

thegunner


1 Answers

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> 
like image 158
Jose Basilio Avatar answered Oct 14 '22 03:10

Jose Basilio