复制代码 代码如下:
<form runat="server">
<asp:DropDownList runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList runat="server">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList runat="server">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
</asp:DropDownList>
<asp:Button runat="server" Text="Button" />
<asp:Panel runat="server">
</asp:Panel>
<asp:Button runat="server" Text="最后一个Button" />
</form>
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Panel1"] != null)
{
int index = this.Form.Controls.IndexOf(Panel1);
this.Form.Controls.RemoveAt(index);
Panel1 = Session["Panel1"] as Panel;
this.Form.Controls.AddAt(index, Panel1);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 3; i++)
{
Label label = new Label();
DropDownList ddl = this.FindControl("DropDownList" + (i + 1).ToString()) as DropDownList;
label.Text = ddl.SelectedValue;
Panel1.Controls.Add(label);
}
Literal br = new Literal();
br.Text = "<br/>";
Panel1.Controls.Add(br);
Session["Panel1"] = Panel1;
}
新闻热点
疑难解答
图片精选