Note that there are some explanatory texts on larger screens.

plurals
  1. POGet JSON data from GridView in ASP.NET?
    primarykey
    data
    text
    <p>im using ASP.NEt to make a simple database query and return JSON formated data. Right now I have the following code which displays the results from database:</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="ScanId" HeaderText="ScanId" ReadOnly="True" SortExpression="ScanId" /&gt; &lt;asp:BoundField DataField="UserId" HeaderText="UserId" SortExpression="UserId" /&gt; &lt;asp:BoundField DataField="barcode" HeaderText="barcode" SortExpression="barcode" /&gt; &lt;asp:BoundField DataField="latitude" HeaderText="latitude" SortExpression="latitude" /&gt; &lt;asp:BoundField DataField="longitude" HeaderText="longitude" SortExpression="longitude" /&gt; &lt;asp:BoundField DataField="date_time" HeaderText="date_time" SortExpression="date_time" /&gt; &lt;asp:BoundField DataField="locatio_name" HeaderText="locatio_name" SortExpression="locatio_name" /&gt; &lt;asp:BoundField DataField="pos_accuracy" HeaderText="pos_accuracy" SortExpression="pos_accuracy" /&gt; &lt;asp:BoundField DataField="pos_country" HeaderText="pos_country" SortExpression="pos_country" /&gt; &lt;asp:BoundField DataField="pos_territory" HeaderText="pos_territory" SortExpression="pos_territory" /&gt; &lt;asp:BoundField DataField="pos_city" HeaderText="pos_city" SortExpression="pos_city" /&gt; &lt;asp:BoundField DataField="pos_street" HeaderText="pos_street" SortExpression="pos_street" /&gt; &lt;asp:BoundField DataField="speed" HeaderText="speed" SortExpression="speed" /&gt; &lt;asp:BoundField DataField="course" HeaderText="course" SortExpression="course" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:dbConnectionString1 %&gt;" ProviderName="&lt;%$ ConnectionStrings:dbConnectionString1.ProviderName %&gt;" SelectCommand="SELECT [ScanId], [UserId], [barcode], [latitude], [longitude], [date_time], [locatio_name], [pos_accuracy], [pos_country], [pos_territory], [pos_city], [pos_street], [speed], [course] FROM [ScanDetails] WHERE [UserId] = '1'"&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p>Can I use this to get data JSON formated? Can you point me in the right direction?</p> <p><strong>EDIT</strong></p> <p>I have a mobile app that loads the .aspx which returns JSON data to the app. So I basically need some sort of Response.Write(json_data); I dont know how to implement that, although I'm searching for possible solutions all day long. I managed to use ADO.NET Entity Data Model and to make queries this way:</p> <p>in controller i did:</p> <p>public class ReadController : Controller {</p> <pre><code> dbEntities1 _db = new dbEntities1(); // // GET: /Read/ public ActionResult Index() { ViewBag.myData = from c in _db.users select c; return View(); } } </code></pre> <p>in view i did:</p> <pre><code>&lt;% foreach (scan_barcode2sql_com.Models.user c in (IEnumerable)ViewBag.myData) { %&gt; &lt;%= c.username %&gt; &lt;% } %&gt; </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.
 

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