问题描述
文本框在单击提交按钮1之后显示数量.我希望选择下拉列表时的数量.代码为.......
受保护的void DropDownList3_SelectedIndexChanged(对象发送者,EventArgs e)
{
con.Open();
SqlCommand cmd1 =新的SqlCommand(从AddedItem中选择数量,其中Item_Name =""+ DropDownList3.SelectedItem.Text +"'',con);
SqlDataReader dr = cmd1.ExecuteReader(CommandBehavior.SingleRow);
如果(dr.Read())
{
TextBox3.Text = dr.GetValue(0).ToString();
dr.Close();
}
}
受保护的void Button1_Click(对象发送者,EventArgs e)
{
字符串st =";
如果(IsPostBack)
{
试试
{
SqlCommand cmd1 =新的SqlCommand(从AddedItem中选择SELECT Item_Id,其中Item_Name =""+ DropDownList3.SelectedItem.Text +"'',con);
SqlDataReader dr = cmd1.ExecuteReader(CommandBehavior.SingleRow);
如果(dr.Read())
{
st = dr [0] .ToString();
dr.Close();
}
SqlCommand cmd =新的SqlCommand("INSERT INTO IssuedItem VALUES(""+ st +"'',''"+ DropDownList1.SelectedItem.Text +"''," + DropDownList2.SelectedItem.Text +'', ''"+ DropDownList3.SelectedItem.Text +"'',''"+ Calendar1.SelectedDate.ToShortDateString()+"'',''"+ TextBox2.Text +"''),con);
cmd.ExecuteNonQuery();
}
捕获(SqlException ex)
{
}
终于
{
con.Close();
}
}
}
Textbox is showing Quantity after submit button1 click.I want Quantity on selection of dropdownlist.code is.......
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd1 = new SqlCommand("SELECT Quantity from AddedItem where Item_Name=''" + DropDownList3.SelectedItem.Text + "''", con);
SqlDataReader dr = cmd1.ExecuteReader(CommandBehavior.SingleRow);
if (dr.Read())
{
TextBox3.Text = dr.GetValue(0).ToString();
dr.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string st = "";
if (IsPostBack)
{
try
{
SqlCommand cmd1 = new SqlCommand("SELECT Item_Id from AddedItem where Item_Name=''" + DropDownList3.SelectedItem.Text + "''", con);
SqlDataReader dr = cmd1.ExecuteReader(CommandBehavior.SingleRow);
if (dr.Read())
{
st = dr[0].ToString();
dr.Close();
}
SqlCommand cmd = new SqlCommand("INSERT INTO IssuedItem VALUES(''" + st + "'',''" + DropDownList1.SelectedItem.Text + "'',''" + DropDownList2.SelectedItem.Text + "'',''"+DropDownList3.SelectedItem.Text+"'',''"+Calendar1.SelectedDate.ToShortDateString()+"'',''"+TextBox2.Text+"'')", con);
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
}
finally
{
con.Close();
}
}
}
推荐答案
这篇关于如何根据下拉列表的选择显示表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!