【问题标题】:How to put 3 GridViews inside a Repeater如何在中继器中放置 3 个 GridView
【发布时间】:2011-10-24 15:38:54
【问题描述】:

我有一个长表,所以我想把它分成 3 个 GridView。每个 GridView 将有不同的标题(来自数据库的不同列)。我想使用一个 SqlDataSource。为此,我正在考虑使用中继器,然后将 3 个 GridViews 放入其中。

由于我使用的 StoredProcedure 要求一个参数来指定每个 GridView 的标题,因此我将该参数设置为 HiddenField,但即使这样我也没有得到任何结果。

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>

            <asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("GroupID")%>' />

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                                SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:ControlParameter ControlID="HiddenField1" />
                </SelectParameters>
            </asp:SqlDataSource>

            <asp:GridView ID="GridView1" runat="server" AllowSorting="True" CellPadding="4" 
                DataKeyNames="BadgeNo" DataSourceID="SqlDataSource1" ForeColor="#333333" 
                GridLines="None">
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:CommandField ShowSelectButton="True" />
                </Columns>
                <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
            </asp:GridView>

        </ItemTemplate>
    </asp:Repeater>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                       ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                       SelectCommand="SELECT DISTINCT GroupID
                                from courses">
    </asp:SqlDataSource>

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    为了解决这个问题,您应该使用plandesign 数据源——您可以使用LinqEntity ModelDataSet。我认为SqlDataSource 在这里不合适。

    在当前的 code-sn-p 中,您应该必须为 GridView 控件设计带有 where 条件/子句 SqlDataSource 的 SELECT - sql 语句。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-30
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 2011-02-10
      相关资源
      最近更新 更多