RSS Feed

Dynamically adding DropDownList using jQuery

September 30, 2011 by Sourabh Sharma

In this article I will show you to add DropDownList dynamically in your ASP.NET Application. I am using jQuery script to do this. This article will help you to whenever you want to add the dropdownlist at run time. You need not to add the dropdownlist control on the Page.


 


Free Download

Dynamic DropDownList : Demo Project

 

jQuery Code to add DropDownList:

<head runat="server">
   <script src="http://code.jquery.com/jquery-latest.min.js">
</script>
<script type="text/javascript">
    $(document).ready(function () {
        var data = { 'Country': 'India', 'Country1': 'USA', 'Country2': 'UK',
 'Country3': 'Rusia', 'Country4': 'France' };
        var s = $('<select />');
        for (var val in data) {
            $('<option />', { value: val, text: data[val] }).appendTo(s);
        }
        s.appendTo('body');
    });
</script>
</head>



No Comments »

No comments yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>