Here is the complete code listing. SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["MyCon"]); protected void txtdeptnos_TextChanged(object sender, EventArgs e) { plcHolder.Controls.Clear(); for (int i = 1; i <= Convert.ToInt32(txtdeptnos.Text); i++) { DropDownList ddl = new DropDownList(); ddl.ID = "ddl" + i.ToString(); ddl.AppendDataBoundItems = true; ddl.Items.Clear(); ddl.Items.Add("Select Department"); ddl.Width = 130; ddl.Items[0].Value = "0"; string strfac = "select deptid,deptname from department where bitDeletedFlag=0"; con.Open(); DataSet ds1 = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(strfac, con); da.Fill(ds1, "department"); ddl.DataSource = ds1.Tables["department"]; ddl.DataTextField = "deptname"; ddl.DataValueField = "deptid"; ddl.DataBind(); con.Close(); plcHolder.Controls.Add(ddl); plcHolder.Controls.Add(new LiteralControl("
")); plcHolder.Controls.Add(new LiteralControl("
")); } } protected void BtnSave_Click(object sender, EventArgs e) { foreach (Control control in this.plcHolder.Controls) { if (control.GetType().Name == "DropDownList") { DropDownList dd = (DropDownList)control; depts = depts + ", " + dd.SelectedItem.ToString(); //I want to concartinate all the selected values of the drop downs and to be inserted into the DB at this click function. But the place holder gets empty. This loop is not executing totally. Session["val"] = dd.SelectedItem.ToString(); } } }
Sagar Pattnayak Software Developer Sun-Dew Solutions +91-9831169962