convert and bind JSON to asp.net gridview convert and bind JSON to asp.net gridview json json

convert and bind JSON to asp.net gridview


I'd solve it like this:

First Step: Download JSON.net

Second Step:

in your CS page

using Newtonsoft.Json;public DataTable DerializeDataTable(){           string json = data; //"data" should contain your JSON     var table = JsonConvert.DeserializeObject<DataTable>(json);    return table;}

now use the function as a datasource to your gridview

protected void btn1_Click(object sender, EventArgs e){GridView1.DataSource = DerializeDataTable();GridView1.DataBind();}

hope this helps


See this question about how to convert your JSON code into a DataSet object (which plays nicely with GridView objects).

From there, you can assign the DataSource property of your GridView to your converted DataSet and then run the DataBind() method.

I personally prefer to use code behind approach when actually rendering the data by using templates and the RowDataBound event to format my data.