Reputation: 45
I want to have "Please select" on top of my dropdownlist, but when I feed the list items from the database the "please select" option is not displaying.
<asp:DropDownList CssClass="form-control" ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource2"
DataTextField="ROLENAME">
<asp:ListItem Text="Please select"
Value="" Disabled="disabled" Selected="True"></asp:ListItem>
</asp:DropDownList>
Upvotes: 0
Views: 3772
Reputation: 1
In .cs code, after DropDownList3.DataBind() insert a ListItem like this:
this.DropDownList3.Items.Insert(0, new ListItem() { Text = "Please select", Value = string.Empty });
Upvotes: 0
Reputation: 35564
Add AppendDataBoundItems="true"
to the DropDownList.
<asp:DropDownList CssClass="form-control" ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource2" AppendDataBoundItems="true"
DataTextField="ROLENAME">
<asp:ListItem Text="Please select" Value="" Enabled="false" Selected="True"></asp:ListItem>
</asp:DropDownList>
And the correct syntax is Enabled="false"
, not Disabled="disabled"
. disabled=disabled is HTML code.
Upvotes: 2