Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to get the selected value of a dynamically generated dropdown.

How to get the selected value of a dynamically generated dropdown.

Scheduled Pinned Locked Moved ASP.NET
helpdatabasetutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SKP24
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • S SKP24

      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

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      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"

      S 1 Reply Last reply
      0
      • A Abhijit Jana

        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"

        S Offline
        S Offline
        SKP24
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups