ASP简单gridview与分页

时间:2014-07-08 11:38:52

标签: c# asp.net gridview

在我的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的数据源没有用于生成列的任何属性或属性。确保您的数据源包含内容。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

将您的属性更改为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将被视为访问说明符。

相关问题