How To Convert And Bind JSON String In To ASP.NET GridView With C#

How To Convert And Bind JSON String In To ASP.NET GridView With C#

Bind GridView from JSON object without AJAX/jQuery and loop in C# also without wrapper class

<!DOCTYPE html>   
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h3>Converted In to Dynamic Object [dynamic keyword]:- Bind GridView From JSON Object </h3>  
        <asp:GridView ID="gdv_JSON2Grid2" runat="server" BackColor="White" BorderColor="#3399ff"  
            BorderStyle="Dotted" BorderWidth="1px" CellPadding="3" GridLines="Both"></asp:GridView>  
  
        <br />  
        <br />  
         <h3>Converted In to DataTable Object [DataTable]:- Bind GridView From JSON Object</h3>  
        <asp:GridView ID="gdv_JSON2Grid2" runat="server" BackColor="White" BorderColor="#3399ff"  
            BorderStyle="Dotted" BorderWidth="1px" CellPadding="3" GridLines="Both"></asp:GridView>  
    </div>  
    </form>  
</body>  
</html>   

in cs:

protected void Page_Load(object sender, EventArgs e)  
        {   
            string DynamicJSON = "[{'Member ID':'1','First Name':'ABC','Last Name':'kumar','Registered Email':'info@minifycode.in','Mobile':'9811111111'}]"; 
  
            //Using  you need to import Newtonsoft.Json  
            dynamic yourObject = JsonConvert.DeserializeObject(DynamicJSON);  
              
            //Binding gridview from dynamic object   
            gdv_JSON2Grid.DataSource = myObject;  
            gdv_JSON2Grid.DataBind();  
  
            //Using DataTable with JsonConvert.DeserializeObject, need to import using System.Data;  
            DataTable yourObjectDT = JsonConvert.DeserializeObject<DataTable>(DynamicJSON);  
  
            //Binding gridview from dynamic object   
            gdv_JSON2Grid.DataSource = yourObjectDT;  
            gdv_JSON2Grid.DataBind();  
          
        } 

2020-02-08