62,046
社区成员
发帖
与我相关
我的任务
分享
<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;
}