tags:

views:

34

answers:

0

I am trying to provide a UI in which we can Reorder the Elements in it. Say for example I have four Panels in a Table as Below

<table id="tblMaster" runat="server">
        <tr id="trOne" runat="server">
            <td>
                Grid One <asp:Panel ID="pnlOne" runat="server">
                    <Kusek:DG Title="One" GridType="1" ID="Demo1" runat="server" />
                </asp:Panel>
            </td>
        </tr>
        <tr id="trTwo" runat="server">
            <td>
               Grid Two <asp:Panel ID="pnlTwo" runat="server">
                    <Kusek:DG  Title="Two" GridType="2" ID="DG1" runat="server" />
                </asp:Panel>
            </td>
        </tr>
        <tr id="trThree" runat="server">
            <td>
               Grid Three <asp:Panel ID="pnlThree" runat="server">
                    <Kusek:DG  Title="Three" GridType="3" ID="DG2" runat="server" />
                </asp:Panel>
            </td>
        </tr>
        <tr id="trFour" runat="server">
            <td>
               Grid Four <asp:Panel ID="pnlFour" runat="server">
                    <Kusek:DG  Title="Three" GridType="3" ID="DG3" runat="server" />
                </asp:Panel>
            </td>
        </tr>
    </table>

And based on a Parameter I wanted to rearrange the Panels in the Table (sometimes I want the pnlOne at the Top, sometime I want pnlFour at the top)and For that I am Doing in the code behind as below.

private void ReOrderTable()
{
    tblMaster.Rows.RemoveAt(3);
    tblMaster.Rows.RemoveAt(2);
    tblMaster.Rows.RemoveAt(1);
    tblMaster.Rows.RemoveAt(0);

    tblMaster.Rows.Insert(0,trThree);
    tblMaster.Rows.Insert(1, trTwo);
    tblMaster.Rows.Insert(2, trOne);
    tblMaster.Rows.Insert(3, trFour);

}

What happens is that during the first page load everything seems to be fine, but after that on each post back It behaves wired, order collapse, I tried to add the code both inside and out side the if(!IsPostBack)

Please let me what is wrong with this and is there a Better way to do it ?