Click here to Skip to main content
15,888,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (IsPostBack && DDLCount > 0)
        {
            CreateDropDownLists();
        }
    }
    public int DDLCount
    {
        get
        {
            object temp = ViewState["DDLCount"];
            return temp == null ? 0 : (int)temp;
        }
        set
        {
            ViewState["DDLCount"] = value;
        }
    }
    private void CreateDropDownLists()
    {
        if (DDLCount == 0)
            DDLCount = Convert.ToInt32(TextBox4.Text);
        for (int i = 0; i < DDLCount; i++)
        {
            DropDownList ddl = new DropDownList();
          
          
            ddl.ID = "Text" + i;
          
            LiteralControl l1 = new LiteralControl("<br></br>");

            SqlConnection con1 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
            con1.Open();
            string st = "select  * from   vassign";  //here   we   have    use     where   cause   minum   number   user   dynamic  control 
            SqlCommand cmd = new SqlCommand(st, con1);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                ddl.Items.Add(dr.GetString(0).ToString());


            }
            con1.Close();
         


            Panel4.Controls.Add(ddl);
                    Panel4.Controls.Add(l1);

        }
    }
  
    protected void Button2_Click(object sender, EventArgs e)
    {
        

       SqlConnection con1 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");

        con1.Open();

        SqlCommand cmd1= new SqlCommand("insert into assign values('" + DropDownList1.SelectedValue.ToString() + "','" + DropDownList2.SelectedValue.ToString() + "','" + TextBox7.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "')", con1);
        cmd1.ExecuteNonQuery();


        con1.Close();

        SqlConnection con2 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
        con2.Open();

        string  str2 = "select   assign_id  from  assign where l_no='" + DropDownList2.SelectedValue + "'";
        SqlCommand cmd2= new SqlCommand(str2, con2);
        SqlDataReader dr2 = cmd2.ExecuteReader();
        dr2.Read();
        int assigned_id = dr2.GetInt32(0);

        con2.Close();  
        string value2 = "";
        for (int i = 0; i < DDLCount; i++)
        {
           
            DropDownList ddl = Panel4.FindControl("Text" + i) as DropDownList;
            value2 = ddl.SelectedValue.ToString();
            SqlConnection con = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("insert into assign_deo values('" + assigned_id + "','" + value2 + "','" + DropDownList1.SelectedValue.ToString() + "')", con);


            cmd.ExecuteNonQuery();

            con.Close();

        }
        DropDownList1.ClearSelection();
        DropDownList2.ClearSelection();
        TextBox7.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        for (int i = 0; i < DDLCount; i++)
        {

            DropDownList ddl = Panel4.FindControl("Text" + i) as DropDownList;
            
          
            ddl.Dispose();

        }

    }
Posted
Updated 6-Jun-12 0:55am
v2
Comments
Sandeep Mewara 6-Jun-12 6:55am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.

hi,
Using jQuery each you can delete dynamically created dropdownlist, try like this:
JavaScript
$("select").each(function () {
    var id = $(this).attr('id');
    if (id.indexOf('Text') >= 0) {
        $(this).remove();
    }
});

here it will delete all dropdownlist which IDs are starting from Text
 
Share this answer
 
C#
Panel1.Controls.Remove(ddl);
 
Share this answer
 

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