在我的頁面上,我有一個DropDownList
,我用SqlDataSource
(請參閱下面的代碼)填充數據庫值。asp.net dropdownlist - 在db值之前添加空白行
如何在值之前添加自己的文本或空白行?
<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>
謝謝。
P.S.你推薦使用SqlDataSource
還是以另一種方式填充?
這涉及到:http://stackoverflow.com/questions/267064/asp-net-add-blank-item-at-top-of-dropdownlist – mcfea 2014-04-16 23:19:03