asp.net的DropDownList - 前分贝值添加空白行 [英] asp.net dropdownlist - add blank line before db values

查看:218
本文介绍了asp.net的DropDownList - 前分贝值添加空白行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网页我有一个的DropDownList 我与数据库值填充从的SqlDataSource (见code以下)。

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>

感谢。

P.S。你推荐使用的SqlDataSource 还是更填充另一种方式?

P.S. Do you recommend using a SqlDataSource or is it better to populate another way?

推荐答案

您可以简单地添加一个的列表项 DropDownList的标记内。所有的数据源中的值将后追加。

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>

这篇关于asp.net的DropDownList - 前分贝值添加空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆