-2

这是我的实体数据源

<asp:EntityDataSource ID="EntityDataSourceCLient" runat="server"
        ConnectionString="name=MBSDbEntities" DefaultContainerName="MBSDbEntities"
        EnableFlattening="False" EntitySetName="ReservationLists" Include="UserProfile" OrderBy="it.Date" Where="">
    </asp:EntityDataSource>

这是我的网格视图

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
        CellPadding="3" DataKeyNames="ID" DataSourceID="EntityDataSourceCLient">
        <Columns>
            <asp:TemplateField HeaderText="UserID" SortExpression="UserProfile.FirstMidname">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("UserProfile.FirstMidname") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("UserProfile.FirstMidname") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="TransactionType" HeaderText="TransactionType" 
                SortExpression="TransactionType" />
            <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
            <asp:BoundField DataField="Status" HeaderText="Status" 
                SortExpression="Status" />
        </Columns>
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <RowStyle ForeColor="#000066" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#007DBB" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#00547E" />
    </asp:GridView>

我可以显示 2 个相关表格,但无法显示特定数量的表格。你们能帮帮我吗?先感谢您。

4

1 回答 1

0

您需要加入表格,然后按您的字段(可能是 TestDate)对它们进行排序,然后使用Enumerable.Take()获取最高5记录。就像是

var query = (from q in table1 
            join r  in table2 on q.UserID equals r.UserID)
            .OrderBy(s=> s.TestDate)
            .Take(5);
于 2013-02-18T10:05:12.500 回答