I’ve got a GridView :
<asp:GridView ID="grdRestitutions" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="JobNumber" HeaderText="Job" />
<asp:BoundField DataField="ContainerType" HeaderText="Type" />
<asp:BoundField DataField="ReleaseDate" HeaderText="Date" />
<asp:BoundField DataField="Commodity" HeaderText="Commodity" />
<asp:BoundField DataField="GrossWeight" HeaderText="Weight" />
<asp:BoundField DataField="SpecialInstructions" HeaderText="Special Instructions" />
</Columns>
</asp:GridView>
That I’m trying to set the DataSource to be a List<Restitution>() where Restitution is a public structure consisting only of public members; i.e.:
public struct Restitution
{
public int ContainerReleasesId;
public int ContainerId;
public System.DateTime ReleaseDate;
public int DepotId;
public string DepotName;
public string JobNumber;
public string BillOfLadingNumber;
public string BookingType;
public string Commodity;
public string SpecialInstructions;
public int GrossWeight;
public bool Confirmed;
public bool RecievedFlag;
public bool ReleaseSource;
public int ContainerTypeId;
public string InOut;
public string ContainerTypeDescription;
}
The data binding looks fairly innocuous, too:
grdRestitutions.DataSource = restitutions;
grdRestitutions.DataBind();
However, an exception is thrown on the DataBind() statement with the less than helpful message of:
“A field or property with the name ‘JobNumber’ was not found on the selected data source.”
I don’t understand why this isn’t working; whilst most examples and use cases seem to use DataSets it does appear that it should support objects implementing IEnumerable. Is there anything special I have to do to allow it to work?
Convert all public fields for public properties and it should work.