Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:32:17+00:00 2026-05-31T05:32:17+00:00

im using ASP.NEt to make a simple database query and return JSON formated data.

  • 0

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:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" 
        EmptyDataText="There are no data records to display.">
    <Columns>
        <asp:BoundField DataField="ScanId" HeaderText="ScanId" ReadOnly="True" 
            SortExpression="ScanId" />
        <asp:BoundField DataField="UserId" HeaderText="UserId" 
            SortExpression="UserId" />
        <asp:BoundField DataField="barcode" HeaderText="barcode" 
            SortExpression="barcode" />
        <asp:BoundField DataField="latitude" HeaderText="latitude" 
            SortExpression="latitude" />
        <asp:BoundField DataField="longitude" HeaderText="longitude" 
            SortExpression="longitude" />
        <asp:BoundField DataField="date_time" HeaderText="date_time" 
            SortExpression="date_time" />
        <asp:BoundField DataField="locatio_name" HeaderText="locatio_name" 
            SortExpression="locatio_name" />
        <asp:BoundField DataField="pos_accuracy" HeaderText="pos_accuracy" 
            SortExpression="pos_accuracy" />
        <asp:BoundField DataField="pos_country" HeaderText="pos_country" 
            SortExpression="pos_country" />
        <asp:BoundField DataField="pos_territory" HeaderText="pos_territory" 
            SortExpression="pos_territory" />
        <asp:BoundField DataField="pos_city" HeaderText="pos_city" 
            SortExpression="pos_city" />
        <asp:BoundField DataField="pos_street" HeaderText="pos_street" 
            SortExpression="pos_street" />
        <asp:BoundField DataField="speed" HeaderText="speed" SortExpression="speed" />
        <asp:BoundField DataField="course" HeaderText="course" 
            SortExpression="course" />
    </Columns>
    </asp:GridView>


    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:dbConnectionString1 %>" 
        ProviderName="<%$ ConnectionStrings:dbConnectionString1.ProviderName %>"       
        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'">
    </asp:SqlDataSource>

Can I use this to get data JSON formated? Can you point me in the right direction?

EDIT

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:

in controller i did:

public class ReadController : Controller
{

    dbEntities1 _db = new dbEntities1();

    //
    // GET: /Read/
    public ActionResult Index()
    {
        ViewBag.myData = from c in _db.users select c;
        return View();
    }

}

in view i did:

<% foreach (scan_barcode2sql_com.Models.user c in (IEnumerable)ViewBag.myData)
{ %>
   <%= c.username %>
<% } %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:32:18+00:00Added an answer on May 31, 2026 at 5:32 am

    Just for completeness…

    The Gridview renders out a HTML table and while it is accessible by Jquery / Javascript to harvest its data, it is easier to simply create an endpoint within your ASP.NET application that can return JSON data. Here are some approaches, my personal favourite would be jQuery to ASP.NET MVC as you can create a controller to handle and render HTML output and JSON data to same model.

    1. ASP.NET MVC : End to end Jquery, Another example using JsonResult object and a broader example
    2. Create a WCF Service. Here you can create a webservice that can run independantly from your website, however, authentication can be a bind when compared to ASP.NET MVC. Examples are from MSDN, using a simple DataContract (that interprets between .NET objects and what should be outputted (lookup Data Transfer Objects [DTO] for further reading). Here’s a walkthrough as well.
    3. Using WebMethod within your code behind. Probably the less impactful for old school ASP.NET developers where you can define methods with the ‘Webmethod’ attribute that will act as a Javascript Endpoint. It can be a bit fiddly (especially compared to MVC) but may take less time on the implementation. Examples are include simple calls and this and something a bit more complex. One thing I would mention is that you do not get any automatic Json serialising (I think) with this technique and you may have to perform the serialisation yourself as shown in this post.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a database application using ASP.NET and I want to make a Windows
My asp.net application is not using formsauthentication. Instead we make a call to database,
I am trying to make a simple web application using ASP.NET and Interop COM.
I'm using Javascript to make a simple image viewer bar for my site (ASP.NET),
I'm trying to make a very simple asp.net page that binds a GridView using
I want to make a login system using ASP.NET (MVC). On the internet, I
I am using asp.net mvc and jquery to make ajax requests and when the
I'm using asp.net membership, and need to make a call to Membership.GetUser() while I
I'm using jQuery and SimpleModal in an ASP.Net project to make some nice dialogs
Is it possible to make a site with ASP.NET MVC Framework using .NET 2.0?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.