Add new value in .net dropdownlist control using jQuery
Posted January 19, 2010
on:Here is your jQuery code:
// first lets un-select any items that have been selected
$(“select.ddlMyDropDown option:selected”).removeAttr(“selected”);
var addvalue = ‘MyNewValue’;
$(“select.ddlMyDropDown”).prepend(‘<option selected=”selected” value=”‘ + addvalue + ‘”>’ + addvalue + ‘</option>’);
Here is your html code:
<asp:DropDownList runat=”server” ID=”ddlMyDropDown” CssClass=”ddlMyDropDown” ></asp:DropDownList>
<br />
<input type=”text” id=”addToDropDown” class=”addToDropDown” visible =”false” size=”1″ />
Nice!
Leave a comment