Binding DropDownList With JQuery And XML.

Posted by Vishalneeraj-24503 under jQuery category on | Points: 40 | Views : 266
Add jQuery library reference in head section and place one dropdown on the page.
Add one list item with select as it's value.

<asp:DropDownList ID="DropDownList1" runat="server">

<asp:Label ID="Label1" runat="server" Text=""/>

Following is the Cities.xml file i'm using to bind dropdownlist using jquery.
<!--?xml version="1.0" encoding="utf-8" ?-->

<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
type: "GET",
url: "Cities.xml",
dataType: "xml",
success: function(xml)
var dropDown = $('#<%=DropDownList1.ClientID %>');
var name = $(this).find('name').text();
var id = $(this).find('id').text();
dropDown.children(":first").text("--Select--").attr("selected", true);
$('#<%=DropDownList1.ClientID %>').change(function()
var ddl = $('#<%=DropDownList1.ClientID %>');
var selectedText = $('#<%=DropDownList1.ClientID %> option:selected').text();
var selectedValue = $('#<%=DropDownList1.ClientID %>').val();
document.getElementById('Label1').innerHTML = "You selected " + selectedText + " With id " + selectedValue;

Comments or Responses

Login to post response