在我的aspx中我有:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="True">
</asp:GridView>
我有一个非常简单的课程:
class ItemTable
{
public ItemTable(string mc, string dt)
{
this.Machinecode = mc;
this.Datetime = dt;
}
string Machinecode { get; set; }
string Datetime { get; set; }
}
在我的代码中:
List<ItemTable> infos = new List<ItemTable>();
//Some code for add item in infos...
GridView1.DataSource = infos;
GridView1.DataBind();
但我有个错误:
id 'GridView1‘的GridView数据源没有任何属性或属性来生成列。确保数据源有内容。
我该怎么解决这个问题?
发布于 2014-07-08 03:40:24
将属性改为public
,如下所示
class ItemTable
{
public ItemTable(string mc, string dt)
{
this.Machinecode = mc;
this.Datetime = dt;
}
public string Machinecode { get; set; }
public string Datetime { get; set; }
}
如果没有提到访问说明符,则将private
作为访问说明符.
https://stackoverflow.com/questions/24630851
复制相似问题