【问题标题】:ASP simple gridview with paging带分页的 ASP 简单网格视图
【发布时间】:2014-07-08 11:38:51
【问题描述】:

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

我该如何解决这个问题?

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多