How to get the selected value of a dynamically generated dropdown.
-
Hi All I am dynamically creating some dropdownlist in the TextBox textchanged event and placing them in a placeholder. Now I want to retrieve all the dropdowns selected value to be inserted into the DB when i press save button. But the problem is that when I press save my place holder gets empty and there is no drop down. How can I do that. I hope I am making sense. Please please help me.....
Sagar Pattnayak Software Developer Sun-Dew Solutions +91-9831169962
-
Hi All I am dynamically creating some dropdownlist in the TextBox textchanged event and placing them in a placeholder. Now I want to retrieve all the dropdowns selected value to be inserted into the DB when i press save button. But the problem is that when I press save my place holder gets empty and there is no drop down. How can I do that. I hope I am making sense. Please please help me.....
Sagar Pattnayak Software Developer Sun-Dew Solutions +91-9831169962
where did you write the code for add the content ? could you put you code over here ?
Best Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"
-
where did you write the code for add the content ? could you put you code over here ?
Best Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"
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