Click here to Skip to main content
15,072,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I want to create panel with label and button (dynamically) on every dropdown selection.
Each time when I select one value in dropdown one panel with label and button should get created and while I select next value in dropdown another panel with label and button should get created. I tried it but when i select next option from dropdown panel for first value is cleared. Please help me.
CHill60 27-Feb-15 6:42am
Share the code you tried

1 solution


<form id="form1" runat="server">
        <asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" xmlns:asp="#unknown">
        <br />
        <asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">
        <asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
        <asp:asyncpostbacktrigger controlid="DropDownList1" />


public partial class _Default : System.Web.UI.Page 
    int i;
    protected void Page_Load(object sender, EventArgs e)
        if (Page.IsPostBack==false)
		 i = 0;
            ViewState["value"] = 0;
        i = int.Parse(ViewState["value"].ToString());

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
         for(int j=0;j<=i;j++)
            Panel pnl=new Panel();
            pnl.ID = j.ToString();
           Button btn= new Button();
           btn.ID = "btn" + j.ToString();
            btn.Text = "btn" + j.ToString();
            pnl.BackColor = System.Drawing.Color.LightGreen;
        i = i + 1;
        ViewState["value"] = i.ToString();
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900