一个Table(一行两列)每个单元格里面有一个Panel,如何点击一个Button交换两个Panel的位置?

解决方案 »

  1.   

    如果需要比较准确地对齐排版,使用<table>.
      

  2.   

    思路:
    button的onClick="switch"
    function:switch()中,通过DOM来操作,交换两个PANELjavascript不是很熟,好像是这样的:
    var table=document.getElementById("table1");
    var panel1=table.childNodes[0];
    var panel2=table.childNodes[1];
    table.removeNamedItem(panel1);
    table.removeNamedItem(panel2);
    table.appendChild(panel2);
    table.appendChild(panel1);
      

  3.   

    this.panel1.location=new point(x,y);
    this.panel2.location=new point(x,y);
    x,y是坐标,你试试了`!!!
      

  4.   

    这个看起来挺好的,试试看吧,
    -----
    给另外一种思路,有些土。
    每个单元格里放两个Panel,通过隐藏Panel来实现楼主的效果。
      

  5.   


     <table style="width: 100%;" id="table1" runat="server">
                <tr>
                    <td>
                        <asp:Panel ID="Panel1" runat="server">
                            <asp:Label ID="Label1" runat="server" Text="Label1" />
                        </asp:Panel>
                    </td>
                    <td>
                        <asp:Panel ID="Panel2" runat="server">
                            <asp:Label ID="Label2" runat="server" Text="Label2" />
                        </asp:Panel>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button ID="Button1" runat="server" Text="点击交换Panel位置" 
                            onclick="Button1_Click" />
                    </td>
                </tr>
    </table>
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                    ViewState["Swap"] = false;                   }        protected void Button1_Click(object sender, EventArgs e)
            {
                bool swap = (bool)ViewState["Swap"];
                swap = !swap;
                if (swap)
                {
                    table1.Rows[0].Cells[0].Controls.Remove(Panel1);
                    table1.Rows[0].Cells[0].Controls.Add(Panel2);
                    table1.Rows[0].Cells[1].Controls.Remove(Panel2);
                    table1.Rows[0].Cells[1].Controls.Add(Panel1);
                }
                else
                {
                    table1.Rows[0].Cells[0].Controls.Remove(Panel2);
                    table1.Rows[0].Cells[0].Controls.Add(Panel1);
                    table1.Rows[0].Cells[1].Controls.Remove(Panel1);
                    table1.Rows[0].Cells[1].Controls.Add(Panel2);
                }
                ViewState["Swap"] = swap;
                
            }
      

  6.   

    你要做的根本需求不会是类似Google的WebPart吧,为什么要按钮呢,感觉需求比较怪,能否说一下具体应用在什么地方,可能有更好的解决方案。