I have a ASP:DropDown list which is populated by the following:
public void Fill1()
{
string connectionString = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
using (SqlConnection _con = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Products", _con))
{
cmd.Connection.Open();
SqlDataReader ddlValues;
ddlValues = cmd.ExecuteReader();
txtProduct.DataSource = ddlValues;
txtProduct.DataValueField = "Description";
txtProduct.DataTextField = "Description";
txtProduct.DataBind();
cmd.Connection.Close();
cmd.Connection.Dispose();
}
}
I need to call the SalesPrice from same table and based on the selected value in the drop down update a ASP:TextBox Field called txtUnitAmount.
I have tried writing it into the same function and it wont let me set the .Text value for the ASP:TextBox. Can any one suggest a way to achieve this?
Thanks to all for their help so far!
Cheers
Justin
Extra Code for Discussion
public void Fill2()
{
string getProdValue = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
using (SqlConnection _con = new SqlConnection(getProdValue))
using (SqlCommand cmd = new SqlCommand("SELECT SalesPrice FROM Products WHERE Description = " + Request.Form["txtProduct"].ToString(), _con))
{
int getProdCost = (int)cmd.ExecuteScalar();
txtUnitAmount.Text = getProdCost.ToString("###,###0.000");
}
}
SQLCommandif you are using ausingblock. Remember all ausingblock is, is simply a try/catch with a dispose in thefinallyblock