C# 无法使用EF、LINQ将网站中的数据打印到列表视图中
我有一个网站,它使用EF构建DB和LINQ来访问数据。我正在尝试将数据打印到列表视图中,但没有打印任何内容,我不知道为什么 标记:C# 无法使用EF、LINQ将网站中的数据打印到列表视图中,c#,asp.net,.net,linq-to-entities,entity-framework-5,C#,Asp.net,.net,Linq To Entities,Entity Framework 5,我有一个网站,它使用EF构建DB和LINQ来访问数据。我正在尝试将数据打印到列表视图中,但没有打印任何内容,我不知道为什么 标记: <asp:ListView ID="lvSearchResults" OnPagePropertiesChanged="lvSearchResults_PagePropertiesChanged" runat="server"> <LayoutTemplate> <table style="width: 100%
<asp:ListView ID="lvSearchResults" OnPagePropertiesChanged="lvSearchResults_PagePropertiesChanged" runat="server">
<LayoutTemplate>
<table style="width: 100%" border="1">
<tr style="text-align:center;">
<td>Item Name</td>
<td>Release Region</td>
<td style="width: 100px">Factory Sealed</td>
<td style="width: 50px">Item Details</td>
<td style="width: 50px">Edit Item</td>
</tr>
<tr id="itemPlaceHolder" runat="server" />
</table>
<asp:DataPager ID="dpSearchResults" PagedControlID="lvSearchResults" PageSize="10" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="false" ShowFirstPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="true" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="true" ShowFirstPageButton="false" ShowLastPageButton="true" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%#:Item.Name%>
</td>
<td>
<%#:Item.Region%>
</td>
<td style="text-align: center;">
<%#:Item.Condition%>
</td>
<td>
<asp:Button ID="btnSelect" Text="View Details" PostBackUrl="/Items/<%#:ItemName%>" runat="server" />
</td>
<td>
<asp:Button ID="btnEdit" Text="Edit Item" PostBackUrl="/Edit/<%#:ItemName%>" runat="server" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
解决方案是添加Eval命令,以使工作代码
<td>
<%#:Eval("Name")%>
</td>
<td>
<%#:Eval("Region")%>
</td>
<td style="text-align: center;">
<%#:Eval("Condition")%>
</td>
<td>
<%#:Eval("Name")%>
</td>
<td>
<%#:Eval("Region")%>
</td>
<td style="text-align: center;">
<%#:Eval("Condition")%>
</td>