Reputation: 121
In my aspx I have:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="True">
</asp:GridView>
I have a very simple class:
class ItemTable
{
public ItemTable(string mc, string dt)
{
this.Machinecode = mc;
this.Datetime = dt;
}
string Machinecode { get; set; }
string Datetime { get; set; }
}
And in my code I have:
List<ItemTable> infos = new List<ItemTable>();
//Some code for add item in infos...
GridView1.DataSource = infos;
GridView1.DataBind();
But i have this error:
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.
How do I fix this ?
Upvotes: 0
Views: 52
Reputation: 48600
Change your properties to public
like this
class ItemTable
{
public ItemTable(string mc, string dt)
{
this.Machinecode = mc;
this.Datetime = dt;
}
public string Machinecode { get; set; }
public string Datetime { get; set; }
}
When no access-specifier is mentioned, private
is taken as access-specifier.
Upvotes: 3