中继器控制中的项目顺序

时间:2011-12-22 09:54:04

标签: asp.net repeater

是否可以在运行时重新排序转发器控件中的行。例如:如果我有转发器控制,如下所示。如果我必须在运行时更改项模板中的表行序列,该怎么办?就像我需要在第一行显示特殊请求然后在第二行中受益,然后根据定义的顺序在第三行中获得首选项。我知道我可以通过制作动态转发器来实现这一目标。但还有其他方法吗?

 <asp:Repeater ID="repGuestInformation" ClientIDMode="AutoID" runat="server" OnItemDataBound="repGuestInformation_ItemDataBound">
            <HeaderTemplate>
                <table>
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Repeater ID="repGuestEventInformation" runat="server" OnItemDataBound="repGuestEventInformation_ItemDataBound">
                   <%-- <HeaderTemplate>


                    </HeaderTemplate>--%>
                    <ItemTemplate>
                    <tr>
                            <td>Registrants</td>
                            <td></td>
                            <td><asp:Label ID="lblCost" runat="server" Text="Cost" /></td>
                            <td></td>
                     </tr>
                     <tr>
                            <td valign="top">
                                <asp:Literal ID="ltlRegistrant" runat="server" />
                                <asp:DropDownList ID="ddlGuest" runat="server" OnSelectedIndexChanged="ddlGuest_SelectedIndexChanged" AutoPostBack="true" />
                                <asp:HiddenField ID="hfRegistrantName" runat="server" />
                            </td>
                            <td>
                                <table>
                                    <tr><td></td><td></td><td></td></tr>
                                    <tr><td></td><td></td><td></td></tr>
                                    <tr><td></td><td></td><td></td></tr>
                                    <tr><td></td><td></td><td></td></tr>
                                    <tr><td></td><td></td><td></td></tr>
                                   <tr><td></td><td></td><td></td></tr>
                                    <tr>
                                        <td>
                                        <%--    Benefits --%>
                                         <asp:Label ID="lblConstituentBenefits" runat="server" Text="Benefits"  ></asp:Label>
                                        </td>
                                        <td></td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td>
                                            <asp:CheckBoxList ID="chkBoxListRegistrantBenefits" runat="server" AutoPostBack="true"
                                                OnSelectedIndexChanged="chkBoxListRegistrantBenefits_SelectedIndexChanged" >
                                            </asp:CheckBoxList>
                                        </td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td>
                                          <%--  Preference--%>
                                            <asp:Label ID="lblConstituentPreference" runat="server" Text="Preference"  ></asp:Label>
                                        </td>
                                        <td></td>
                                        <td></td>
                                     </tr>
                                     <asp:Repeater ID="repEventPreference" runat="server" OnItemDataBound="repEventPreference_ItemDataBound">
                                        <ItemTemplate>
                                                <tr>
                                                <td></td>
                                                    <td>
                                                            <asp:Literal ID="ltlEventPreference" runat="server" />
                                                            <asp:HiddenField ID="hfID" runat="server" />
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddlEventPreference" runat="server" AppendDataBoundItems="true"
                                                            AutoPostBack="true" OnSelectedIndexChanged="ddlEventPreference_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                        </ItemTemplate>
                                     </asp:Repeater>
                                    <tr>
                                        <td>
                                           <%-- Special Requests--%>
                                            <asp:Label ID="lblConstituentSpecialRequest" runat="server" Text="Special Requests"  ></asp:Label>
                                        </td>
                                        <td></td>
                                        <td></td>
                                     </tr>
                                    <tr>
                                        <td></td>
                                        <td>
                                            <asp:CheckBoxList ID="chkBoxListSR" runat="server" AutoPostBack="true" OnSelectedIndexChanged="chkBoxListSR_SelectedIndexChanged">
                                            </asp:CheckBoxList>
                                        </td>
                                        <td></td>
                                     </tr>
                                    <tr>
                                        <td>
                                            <asp:Panel ID="registrantAttPanel" runat="server" />
                                        </td>
                                        <td></td>
                                        <td></td>
                                     </tr>
                                 </table>
                            </td>
                            <td valign="top" style="padding-top:7px;">
                            <asp:Literal ID="ltlCost" runat="server" /><asp:HiddenField ID="hfID" runat="server" />
                            </td>

                            <td valign="top">
                            <asp:Button ID="btnClearRow2" CausesValidation="false" runat="server" Text="CLEAR" OnClick="btnClearRow2_Click" />
                            </td>
                      </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

1 个答案:

答案 0 :(得分:5)

当您绑定到转发器时,绑定的项目将按照它们在包含它们的集合中的顺序进行绑定。

您可以在绑定前重新排序集合。