Convert Dataset Datatable To Json Data Array in Asp.Net C#.Net & VB.Net or How To Use JavaScriptSerializer to Convert Datatable to Json Data Array

In this tutorial i am going to explain about how to convert dataset datatable to json data array in asp.net c#.net & vb.net or how to use JavaScriptSerializer to convert datatable to json data array


In my previous article i have explained about Highlight,Change Color Of Row On Mouseover In Grid View Using CSS – C#.Net ASP.Net VB.Net,Programmatically Group Gridview Column Headers,How To Convert JSON Data Into Html Table Using Javascript JQuery,Upload Multiple Files In Asp.Net C#.Net VB.Net / Maximum Request Length Exceeded,Change Row Color Of A Grid View Based On Particular Condition, and many articles in C#.Net,ASP.Net,VB.Net,Grid View,Javascript,jQuery,JSON and many other topics.

To start explaining about how to convert dataset datatable to json data array in asp.net c#.net & vb.net or how to use JavaScriptSerializer to convert datatable to json data array i am creating a new website in visual studio and in default.aspx file i have added a gridview control from the toolbox. And also i have added a div to display the json data. The gridview is used to bind gridview data and the div is used to bind the json array.The entire html markup is given below.

HTML Markup:

Datatable:

Equivalent JSON Data Array:

Now before proceeding to explain about how to convert dataset datatable to json data array in asp.net c#.net & vb.net or how to use JavaScriptSerializer to convert datatable to json data array please include below namespaces in your code behind file.

C#.Net:

VB.Net:

Now in the page load event i have created a datatable with some columns and inserted some sample records into that datatable. After that i have binded that datatable to gridview and then using the GetJson method defined in my code behind file i have converted the datatable into json dataarray. In the GetJson method the datatable is first converted into Dictionary object and then using Serialize method of JavaScriptSerializer class which is in System.Web.Script.Serialization namespace is used to serialize the dictionary object into json data array and then it is displayed in the div. The entire code is given below.

C#.Net:

VB.Net:

The output will look like the below screenshot.

Output of Convert Dataset Datatable To Json Data Array in Asp.Net C#.Net & VB.Net or How To Use JavaScriptSerializer to Convert Datatable to Json Data Array
Sourcecode of Convert Dataset Datatable To Json Data Array in Asp.Net C#.Net & VB.Net
 Convert Dataset Datatable To Json Data Array in Asp.Net C#.Net & VB.Net or How To Use JavaScriptSerializer to Convert Datatable to Json Data Array
 
You May Also Like…

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!