Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If still need help please </p> <p>ASPX CODE:</p> <pre><code> &lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="Scripts/jquery-1.4.1.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" language="javascript"&gt; $(document).ready(function () { $.ajax ({ type: "POST", url: "test.aspx/options", data: '', contentType: "application/json;charset=utf-8", dataType: "json", success: function (data) { var lankanListArray = JSON.parse(data.d); // running a loop $.each(lankanListArray, function (index, value) { $("#ddlCountry").append($("&lt;option&gt;&lt;/option&gt;").val(this.name).html(this.price)); }); }, error: function (err) { } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:DropDownList ID="ddlCountry" runat="server" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; C# CODE using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using MailDLL; using System.Web.Services; using System.Web.Script.Serialization; public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static string options() { JavaScriptSerializer serializer = new JavaScriptSerializer(); landmarkEntities A = new landmarkEntities(); var b = A.sp_test().ToList(); List&lt;Test1&gt; c=new List&lt;Test1&gt;(); foreach (var s in b) { Test1 testobj = new Test1(); testobj.name = s.Name; testobj.price = s.price; c.Add(testobj); } string jsonString = serializer.Serialize(c); return jsonString; } public class Test1 { public Test1(string _name, string _price) { name = _name; price = _price; } public Test1() { } public string name { get; set; } public string price { get; set; } } } first add refrence to these js files in your application. &lt;script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="Scripts/jquery-1.4.1.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"&gt;&lt;/script&gt; then create class that will hold the data public class Test1 { public Test1(string _name, string _price) { name = _name; price = _price; } public Test1() { } public string name { get; set; } public string price { get; set; } } add using System.Web.Script.Serialization; in your cs page so that you can use JavaScriptSerializer. the create a list of type class. Loop through the data. inside loop create object of a class. assign the data that you had fetched to the class, add the object to the list of type class. then Serialize the list using serializer.Serialize() function.And return as string. string jsonString = serializer.Serialize(c); return jsonString; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload