我有一个可从下拉列表中选择的名称列表。名称是从数据源而不是从ListItem中提取的。我想在没有选择的情况下将框留空。我怎样才能做到这一点?
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="director"
DataValueField="director">
<!--<asp:ListItem Text="Please Select Director" Value="-1"/>-->
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:dvdsConnectionString %>" ProviderName="<%$
ConnectionStrings:dvdsConnectionString.ProviderName %>"
SelectCommand="SELECT [director] FROM [dvds]">
</asp:SqlDataSource>
答案 0 :(得分:0)
尝试将AppendDataBoundItems="True"
添加到代码中,并将<asp:ListItem Selected="True"></asp:ListItem>
添加为项目
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="director"
DataValueField="director" AppendDataBoundItems="True">
<asp:ListItem Selected="True"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:dvdsConnectionString %>" ProviderName="<%$
ConnectionStrings:dvdsConnectionString.ProviderName %>"
SelectCommand="SELECT [director] FROM [dvds]">
</asp:SqlDataSource>