2

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>
Shankar Das
  • 117
  • 1
  • 4
  • 14

1 Answers1

6

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.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • how can I reorder the collection? – Shankar Das Dec 22 '11 at 09:58
  • @user1075000 - http://stackoverflow.com/questions/3630687/how-to-sort-an-ienumerablestring – Oded Dec 22 '11 at 09:59
  • Basically I have two reorder the rows inside repeater. like first row can be second and second row can be first sometimes. – Shankar Das Dec 22 '11 at 10:06
  • @user1075000 - A repeater simply reflects the data in the collection. If you need reordering, do that on the collection before re-binding. – Oded Dec 22 '11 at 10:08
  • @Oded- Do you have any example for that? Am not getting your answer. I just need to re-order the rows in repeater item template according to sequence. – Shankar Das Dec 22 '11 at 10:29
  • @user1075000 - You are binding a sequence to the repeater, right? Reorder the sequence. Did you read the link I posted? – Oded Dec 22 '11 at 10:31
  • @Oded- yes but it not what actually I need. – Shankar Das Dec 22 '11 at 11:20
  • @user1075000 - You will need to explain better, as I don't understand what you need. Why not edit your question and add more details to it? Things like _where_ the reordering occurs (server/client), how you want it to work etc... – Oded Dec 22 '11 at 12:31
  • I have edited my question. Basically I need to customize the repeater layout at runtime without making the repeater dynamic. – Shankar Das Dec 23 '11 at 13:57