Can we Bind Json String data directly to the gridview
until what i've done is
C#
string dtRecon = oReportsBLL.Initiate3WayRecon(objreports);
if(dtRecon !=null && dtRecon.Length > 0)
{
grd3wayInitiate.DataSource = dtRecon ;
grd3wayInitiate.DataBind();
}and my response is like

i just want to bind the result as it is to my gridview
Can this be done? if ok pls help me
if this can't be then give me a suggestion
and i dont want to deserialize it just show as it is in the grid like json pls help me
and my grid design
Code

Amit MohantyRank #112 · 20K reputationPosted Feb 29, 2024, 2:46 AM EST
No, you cannot directly bind JSON string data to a GridView control. However, you can parse the JSON string into a collection of objects (such as a list of custom classes or a DataTable) and then bind that collection to the GridView.
Example 1: By DataTable
Example 2: By Custom Class
List customClasses = DeserializeJson>(yourJsonString); gridView.DataSource = customClasses; gridView.DataBind(); private T DeserializeJson(string jsonString) { JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Deserialize(jsonString); } public class CustomClass { public string PropertyOne{ get; set; } public int PropertyTwo{ get; set; } }Rajeesh MenothRank #118 · 18.4K reputationPosted Feb 28, 2024, 6:28 AM EST
Hi,
You can try this :
https://learn.microsoft.com/en-us/answers/questions/715354/how-to-display-json-data-into-gridview
Vishal YelveRank #178 · 13.6K reputationPosted Feb 28, 2024, 9:18 AM EST
Hi Jaya,
do refer below article
https://www.c-sharpcorner.com/article/how-to-convert-and-bind-json-string-in-to-asp-net-gridview-with-c-sharp/
Sam HobbsRank #107 · 20.5K reputationPosted Feb 28, 2024, 3:53 PM EST
If the sample JSON data you show here was shown as text then I could be more specific but it is instead shown here as an image.
If I understand your question then you must deserialize the JSON.
Jignesh KumarRank #91 · 22.9K reputationPosted Feb 28, 2024, 10:45 PM EST
Hello Jaya Prakash,
Please deserialize your jason string in to data table,
string strJsonRecon = oReportsBLL.Initiate3WayRecon(objreports); // Add this line to deserialize your json data to datatable. DataTable dtRecon = JsonConvert.DeserializeObject(strJsonRecon); if(dtRecon !=null && dtRecon.Length > 0) { grd3wayInitiate.DataSource = dtRecon ; grd3wayInitiate.DataBind(); }