ID 为“GridView1”的 GridView 的数据源在 asp .net 中没有任何属性或特性
本文关键字:任何 属性 net asp GridView1 GridView 数据源 ID | 更新日期: 2023-09-27 18:34:36
这是我的默认值.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
{
}
}
它显示错误,如下所示:
ID 为"GridView1"的 GridView 的数据源没有任何要从中生成列的属性或特性。 确保数据源包含内容。
在我现有的代码中,显示文本框中以json输出,http://s30.postimg.org/p8dx9p33l/untitled.jpg
为了仅在网格视图中显示文本框中的json数据,我更改了上面的代码。
我是 .net 的新手,任何人都可以帮我解决这个问题,
任何帮助将不胜感激。
提前谢谢。
Product
类没有从中生成列的属性。您需要在类Product
定义属性。
public class Product
{
public long id{ get; set; }
public string title{ get; set; }
public string body_html{ get; set; }
}
以及要在网格视图中显示为列的其他属性。