4
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
DataTable dt = JsonConvert.DeserializeObject<DataTable>(yourJsonString);
GridView1.DataSource = dt;
GridView1.DataBind();
Example 2: By Custom Class
List<CustomClass> customClasses = DeserializeJson<List<CustomClass>>(yourJsonString);
gridView.DataSource = customClasses;
gridView.DataBind();
private T DeserializeJson<T>(string jsonString)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Deserialize<T>(jsonString);
}
public class CustomClass
{
public string PropertyOne{ get; set; }
public int PropertyTwo{ get; set; }
}
Accepted 3
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<DataTable>(strJsonRecon);
if(dtRecon !=null && dtRecon.Length > 0)
{
grd3wayInitiate.DataSource = dtRecon ;
grd3wayInitiate.DataBind();
}
3
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.
3
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/
3
Hi,
You can try this :
https://learn.microsoft.com/en-us/answers/questions/715354/how-to-display-json-data-into-gridview