<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dropdown with JSON.aspx.cs" Inherits="Dropdown_with_JSON" EnableEventValidation="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="Scripts/jquery-1.8.2.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Jquery.asmx/BindDropdown", data: "{}", dataType: "json", success: function (data) { $("#DropDownList1").append($("<option></option>").val("").html("srre")); $.each(data.d, function (key, value) { $("#DropDownList1").append('<option value="' + value.CategoryID+ '">' + value.CategoryName + '</option>'); }); }, error: function (result) { alert("Error"); } }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <br /> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> </div> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)