我有一个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>
我正在尝试将DataSource设置为一个List<Restitution>()
,其中Restitution
是一个公共结构体,只包含公共成员,即:
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;
}
数据绑定看起来也相当无害:
grdRestitutions.DataSource = restitutions;
grdRestitutions.DataBind();
然而,在DataBind()
语句中抛出了一个异常,错误信息并不是很有用:我不明白为什么它不起作用;虽然大多数示例和用例似乎使用"在所选数据源中未找到名称为'JobNumber'的字段或属性。"
DataSet
,但它似乎应该支持实现IEnumerable
的对象。我需要做特殊的事情来使它工作吗?