删除动态创建的下拉列表 [英] Delete Dynamic created dropdownlist

查看:84
本文介绍了删除动态创建的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();

        }

    }

推荐答案


使用jQuery 每个,您可以删除动态创建的下拉列表,请尝试如下操作:

Using jQuery each you can delete dynamically created dropdownlist, try like this:


(" ).each(函数(){ var id =
("select").each(function () { var id =


( this ).attr(' id'); 如果(id.indexOf(' 文本')> = 0 ){
(this).attr('id'); if (id.indexOf('Text') >= 0) {


这篇关于删除动态创建的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆