I have a list of names to select from a dropdown list. The names are being pulled from a data source and not from a ListItem. I want to leave the box blank while no selection has been. How can I do this?
<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>
Try add AppendDataBoundItems="True"
to the tag and add <asp:ListItem Selected="True"></asp:ListItem>
as an item
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.