2
votes

Is it possible to re-order the rows in repeater control at run time. for example: if I I have repeater control as shown bellow. What if I have to change the sequence of rows of table in item template at run time. Like I need to show the special requests in first row then benefits in second row and then preferences in third row according to the sequence defined. I know I can do it by making it dynamic repeater. But Is there any other way?

 <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

1 Answers

6
votes

When you bind to the repeater, the bound items will be bound in the order they are in the collection holding them.

You can reorder the collection before binding.