I have an asp:DetailsView with several columns, e.g. Foo, Bar.
I want to fill it with an anonymous type, i.e.:
gridView.DataSource = new { Foo = 1, Bar = "2" };
gridVeew.DataBind();
But getting next error:
Data source is an invalid type. It
must be either an IListSource,
IEnumerable, or IDataSource.
How can I do what I want?
The DataSource property expects a collection. The value you are assigning is not a collection.
You will have to create a collection and put the anonymous typed instance into that collection. The following should probably work (though I’ve not tested it with DataSource):