I have a dropdownlist with a disabled initial value "Please select value" and when I click it, it appears again as one of the selections. Is there a way to remove this such that I will only see my items, and not see "Please select value" from the choices of selection?
<asp:DropDownList ID="ddlRole" runat="server" AppendDataBoundItems="true" Width="115">
<asp:ListItem Selected="True" Text="Please select value" Value="" disabled />
</asp:DropDownList>
<asp:DropDownList ID="ddlRole" runat="server" AppendDataBoundItems="true" Width="115" onclick="removeFirst()">
<asp:ListItem Selected="True" Text="Please select value" Value="plsselect" />
<asp:ListItem>First Item</asp:ListItem>
<asp:ListItem>Second Item</asp:ListItem>
</asp:DropDownList>
And in Javascript
<script>
function removeFirst() {
var select = document.getElementById('<%= ddlRole.ClientID %>');
for (i = 0; i < select.length; i++) {
if (select.options[i].value == 'plsselect') {
select.remove(i);
}
}
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With