2017-03-07 36 views
0

我有一个ASP.NET网站的中继器,我想只显示3记录 中继器:如何显示前3名的记录

<asp:Repeater ID="repNews" runat="server" DataSourceID="EntityDataSource1"> 
    <ItemTemplate> 
     <ul> 
     <li><a href='<%# Eval("news_link")%>' > <asp:Label ID="lblNews" runat="server" Text='<%# Eval("news_title")%>' /></a></li> 
     </ul> 
    </ItemTemplate> 

和实体模型

</asp:Repeater> 
    <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=AGIP_dbEntities" DefaultContainerName="AGIP_dbEntities" EnableFlattening="False" EntitySetName="tbl_news" > 
    </asp:EntityDataSource> 
+1

您好,请阅读[常见问题]和[问]。然后回来编辑你的问题。 – Marco

+0

向我们展示您的实体框架当前代码。 –

+0

您可以使用.Take,https://msdn.microsoft.com/en-us/library/bb300906(v=vs.110).aspx – Adil

回答

1

感谢球员,但我尝试这个和这个工作

Select="top(2) it.news_title,it.news_link" 

在entitydatasoruce

添加它

会是这样

<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=AGIP_dbEntities" DefaultContainerName="AGIP_dbEntities" EnableFlattening="False" EntitySetName="tbl_news" Select="top(2) it.news_title,it.news_link"> 
    </asp:EntityDataSource>