Saturday, March 23, 2013

Remove DropDownList value on select change


Consider the below dropdown list.

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Select Below</asp:ListItem>
<asp:ListItem>aaaa</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>
<asp:ListItem>ccc</asp:ListItem>
<asp:ListItem>ddd</asp:ListItem>
</asp:DropDownList>

Lets say we need to remove the item at 0th index when user selects an item from the list.

Jquery Script:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript"> 
 $(document).ready(function () { 

 $("#<#= DropDownList1.ClientID #>").change(function () {

 $("#<#= DropDownList1.ClientID #> option[value='0']").remove();
 }); 

 }); 

</script>

No comments:
Write comments
Recommended Posts × +