Asp.net 将项目从文本框添加到下拉列表,并将其存储在数据库中
我有两个下拉列表,我想通过文本框在其中添加更多的项目,并将它们存储到数据库中Asp.net 将项目从文本框添加到下拉列表,并将其存储在数据库中,asp.net,sql-server,Asp.net,Sql Server,我有两个下拉列表,我想通过文本框在其中添加更多的项目,并将它们存储到数据库中 protected void ddlDisp_SelectedIndexChanged(object sender, EventArgs e) { try { if (ddlDisp.SelectedIndex != 0) { String strConnString = ConfigurationManager.ConnectionString
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();
}
}
当你问1时要清楚。其中的
意味着你能推断出两个下拉列表吗?你想添加到文本框的下拉列表中吗?因此,您使用另一个按钮(如save
)或在Textbox的textchanged事件上进行添加?我不想添加下拉列表。我想添加textbox,通过它我可以在点击按钮时向下拉列表中添加值。您是否创建了1.textbox标记并添加了Textchange事件,Postback=true,在该调用中,此下拉列表绑定向下拉列表中添加了新项。我添加了textbox,其值在下拉列表中出现。问题是如何将其保存在数据库中执行此操作的一种方法是,我假设下拉列表值将位于单独的表中,所以当您将该值绑定到文本框更改事件中的下拉列表时,最好将该值添加到数据库中。作为单独的insert语句
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 !!!";
}
}