【发布时间】:2016-08-30 09:13:32
【问题描述】:
我正在尝试做发票项目,当我选择下拉列表项目时,我应该从数据库中获取价格和折扣并显示在文本框中,并且我正在将价格值获取到文本框中,但是我怎样才能获得另一个值是折扣到文本框我如何绑定第二个文本框值...请一些人帮我....谢谢你
protected void Page_Load(object sender, EventArgs e)
{
if (! IsPostBack )
{
populatedropproduct();
}
}
private void populatedropproduct()
{
SqlCommand com = new SqlCommand("SELECT * FROM invoice1", conn);
com.Connection.Open();
SqlDataReader rdr = com.ExecuteReader();
dropproduct.DataSource = null;
dropproduct.DataTextField = "PRODUCT_NAME";
dropproduct.DataValueField ="PRICE";
dropproduct.DataBind();
dropproduct.Items.Insert(0, new ListItem("--Select Item--", "0"));
com.Connection.Close();
}
protected void txtinvoice_TextChanged(object sender, EventArgs e)
{
}
protected void txtcustomer_TextChanged(object sender, EventArgs e)
{
}
protected void dropproduct_SelectedIndexChanged(object sender, EventArgs e)
{
String title = dropproduct.SelectedItem.Value;
title = dropproduct.SelectedItem.Value;
try
{
SqlCommand com = new SqlCommand("SELECT PRICE,[DISCOUNT%] FROM invoice1 WHERE [PRODUCT NAME]=@title", conn);
SqlParameter param0 = new SqlParameter();
param0.ParameterName = "@title";
param0.SqlDbType = System.Data.SqlDbType.NVarChar;
param0.Value = title;
com.Parameters.Add(param0);
com.Connection.Open();
SqlDataReader rdr = com.ExecuteReader();
txtprice.Text = title.ToString();
com.Connection.Close();
com.Connection.Dispose();
}
catch(Exception s)
{
HttpContext.Current.Response.Write("Error Occured " + s.Message);
}
}
【问题讨论】:
-
这个
System.Data.SqlDbType.Int应该是System.Data.SqlDbType.Varchar -
谢谢你.....它的工作,我如何才能将另一个文本值绑定到文本框中,如上述代码中的价格,请帮助我
标签: c# sql asp.net visual-studio