Adnan Khan

Add new value in .net dropdownlist control using jQuery

Posted on: January 19, 2010


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

Blog Stats

  • 13,100 hits

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 14 other subscribers

Monthly Archives

My Delicio Links