我有以下代码:
<asp:ListView ID="lvDetail" runat="server"> <ItemTemplate> <tr> <td><%# Eval("ShpNo")%></td> <td><%# Eval("QtyShp")%></td> <td><%# Eval("NumPallets")%></td> </tr> </ItemTemplate> <LayoutTemplate> <table id="tbl1" runat="server"> <tr id="tr1" runat="server"> <td id="td1" runat="server">ShpNo</td> <td id="td2" runat="server">QtyShp</td> <td id="td3" runat="server">NumPallets</td> </tr> <tr id="ItemPlaceholder" runat="server"> </tr> </table> </LayoutTemplate> </asp:ListView>
并在代码背后:
List<Visibility> ListVisibility = new List<Visibility>(); public class Visibility { public int ShpNo; public int QtyShp; public int NumPallets; public string ETA; } List<Visibility> items = ListVisibility.FindAll(VisibItem => VisibItem.ETA == Calendar1.SelectedDate.ToShortDateString()); lvDetail.DataSource = items; lvDetail.DataBind();
但绑定时我收到以下错误:
< td><%#Eval(“ShpNo”)%>< / td>
DataBinding:’AIS.WebVisibility Visibility’不包含名为’ShpNo’的属性.
为了从List中获取正确的值,我需要做什么?
解决方法
你有字段而不是属性
public class Visibility { public int ShpNo { get; set; } public int QtyShp { get; set; } public int NumPallets { get; set; } public string ETA { get; set; } }
试试看