---
title: "DataTables in ASP.net using JSON"  
description: "DataTables in ASP.net using JSON"  
author: "marcel ethan"  
published: 2014-12-09  
updated: 2014-12-10  
canonical: https://www.mindstick.com/forum/12774/datatables-in-asp-dot-net-using-json  
category: "asp.net"  
tags: ["c#", "json"]  
reading_time: 2 minutes  

---

# DataTables in ASP.net using JSON

Using JQuery DataTables in [ASP.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) and [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to return [JSON data](https://www.mindstick.com/forum/782/how-to-send-request-amp-amp-response-from-json-data-using-asp-dot-net) to it from [C# WebMethod](https://www.mindstick.com/forum/12733/how-to-call-a-c-sharp-webmethod-on-mouseover-of-linkbutton-in-asp-dot-net).

## C# [method](https://www.mindstick.com/forum/166/webservice-method)...

```
[System.Web.Services.WebMethod][ScriptMethod(ResponseFormat = ResponseFormat.Json)]public static string Data(){    string json =string.Empty;     using (IDataReader reader = DBUtil.GetReader("data", "data",
"pram"))    {        if (reader !=null)        {            DataTable dt = new DataTable();           
dt.Load(reader);           
reader.Close();            json =JsonHelper.GetJsonFromDataTable(dt);        }    }    return json;   //also tried by adding
"{\"aaData\": " + json + "}"}
```

Working....

```
var source = {};$.ajax({    type: 'POST',    dataType: 'json',    url: "page.aspx/Data",    contentType: 'application/json; charset=utf-8',    cache: false,    data: {},    success: function (response) {        source = $.parseJSON(response.d);        alert(response.d); // i can see Json formatted data     },    error: function (XMLHttpRequest, textStatus, errorThrown) {        alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);    }});
```

Not working....... (not even hitting the method break point)

```
$(".JGrid").dataTable({    "bJQueryUI": true,    "sAjaxSource": "../page.aspx/Data", //also tried with var 'source' (declared sbove)    "aoColumns": [        { "sTitle": "Col1name", "sWidth": "33%" },        { "sTitle": "Col2name", "sWidth": "33%" },        { "sTitle": "Col3name", "sWidth": "33%" }    ]});
```

## Replies

### Reply by Anonymous User

```
$(".JGrid").dataTable({   
"bJQueryUI": true,"bServerSide": true,   
"sAjaxSource": "/page.aspx/Data", //also tried with
var 'source' (declared sbove)   
"aoColumns": [        { "sTitle":"Col1name", "sWidth": "33%" },        {
"sTitle": "Col2name", "sWidth": "33%"
},        {
"sTitle": "Col3name", "sWidth": "33%" }    ]});
```

### Reply by Anonymous User

```
$("#table-tripNote").dataTable({               
"oLanguage": {                   
"sZeroRecords": "No records to display",                   
"sSearch": "Search from all Records"                },               
"bProcessing": true,               
"bServerSide": true,               
"bDestroy": true,                "sAjaxSource":"frmTrip.aspx/GetMemberNotesByTrip",               
"sPaginationType": "full_numbers",               
"bDeferRender": true,               
"aoColumns":                           
[                                null,                                null,                                null,                                null,                                null,                                null,                                null                           
],               
"fnServerData": function (sSource, aoData, fnCallback) {                   
$.ajax({                       
"dataType": 'json',                       
"contentType": "application/json; charset=utf-8",                       
"type": "GET",                       
"url": sSource,                       
"data": aoData,                       
"success":                                                   
function (msg) {                                                        
var json = jQuery.parseJSON(msg.d);                                                       
fnCallback(json);                                                       
$("#table-tripNote").show();                                                   
}                    });                }            });
```

This was working for me


---

Original Source: https://www.mindstick.com/forum/12774/datatables-in-asp-dot-net-using-json

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
