将项目从文本框添加到下拉列表并将其存储在数据库中

时间:2017-04-17 06:01:15

标签: asp.net sql-server

我有两个下拉列表我想通过文本框添加更多项目并将它们存储到数据库中

protected void ddlDisp_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {

        if (ddlDisp.SelectedIndex != 0)
        {
            String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;            
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd=new SqlCommand();
            SqlDataAdapter sda = new SqlDataAdapter();
            DataSet dsSubDisp = new DataSet();

            using (cmd = new SqlCommand("Select distinct CallType,Disposition,SubDisposition,Format from  Loy_DispMstr where CallType=@CallType and SUBFormat=@Format and Disposition = @disposition", con))
            {
                cmd.Parameters.AddWithValue("@CallType",ddlCalltype.SelectedValue);
                cmd.Parameters.AddWithValue("@Format", ddlFormat.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@disposition", ddlDisp.SelectedValue);
                con.Open();
                cmd.ExecuteNonQuery();

            }
            sda.SelectCommand = cmd;
            sda.Fill(dsSubDisp);
               {

                    ddlSubdisp.DataTextField = "SubDisposition";
                    ddlSubdisp.DataValueField = "SubDisposition";
                    ddlSubdisp.DataSource = dsSubDisp.Tables[0];
                    ddlSubdisp.DataBind();

                    ddlSubdisp.Items.Insert(0, "<----Select---->");
                    ddlSubdisp.SelectedIndex = 0;
                    ddlSubdisp.Focus();

                }
            }

catch(Exception ex)             {}             }

  

从此我可以将插入的项目从文本框保存到下拉列表

     

从此我可以将插入的项目从文本框保存到下拉列表

     

从此我可以将插入的项目从文本框保存到下拉列表

   protected void Button4_Click(object sender, EventArgs e)
   {

       if (TextBox1.Text == "" && TextBox2.Text == "")
       {
           Label2.Text = "Enter Value !!";
           TextBox1.Focus();
           TextBox2.Focus();
           Label2.Visible = CheckBox1.Checked;
       }
       else
       {
           ddlDisp.Items.Add(TextBox1.Text);
           ddlSubdisp.Items.Add(TextBox2.Text);
           Label2.Text = "Item Added Successfully !!!";

       }

   }

0 个答案:

没有答案