I have created dynamically 5 Dropdown List. It is from aspx.cs

for (int i = 0; i < 5; i++)
            {
                DropDownList drop = new DropDownList();
                drop.ID = "dropdownlist" + i;
                form1.Controls.Add(drop);
                form1.Controls.Add(new LiteralControl("<br />"));
             }

I already have another dropdown code like

if (!this.IsPostBack)
        {
            string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT ID, Name FROM RejectedProduct"))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = con;
                    con.Open();
                    DropDownList1.DataSource = cmd.ExecuteReader();
                    DropDownList1.DataTextField = "Name";
                    DropDownList1.DataValueField = "ID";
                    DropDownList1.DataBind();
                    con.Close();
                }
            }
            DropDownList1.Items.Insert(0, new ListItem("Select Item for adding", "0"));}

How I can use this code for dynamically Creating new 5 dropdown each?

Related posts

Recent Viewed