Reputation: 1854
Here is my default.aspx:
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ShopifyAuthorizationState state = HttpContext.Current.Session["Shopify.AuthState"] as ShopifyAuthorizationState;
ShopifyAPIClient client
= new ShopifyAPIClient(state);
string shopData = (string)client.Get("/admin/products.json");
JavaScriptSerializer serializer = new JavaScriptSerializer();
// Here Product is a object class which contains all of the attribute that JSON has.
List<Product> lstProduct = serializer.Deserialize<List<Product>>(shopData);
GridView1.DataSource = lstProduct;
GridView1.DataBind();
}
public class Product
{
}
}
It shows error, like this:
The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.
In my existing code shows is output in json in text box, http://s30.postimg.org/p8dx9p33l/untitled.jpg
For displaying json data in text box into gridview only, i changed the above code.
I m new to .net, can anyone help me to fix this,
Any help would be highly appreciated.
Thanks in advance.
Upvotes: 0
Views: 4127
Reputation: 14624
Your Product
class doesn't have properties from which columns would be generated. You need to define properties in Product
class.
public class Product
{
public long id{ get; set; }
public string title{ get; set; }
public string body_html{ get; set; }
}
And other properties which you want to show in gridview as column.
Upvotes: 5