EDN Admin
Well-known member
I have a created a mini web app, the goal is to have the price displayed on a textbox. I was already able to populate the dropdownlist with the product names what I want to happen is there would be a textbox that would display the price of the current selected
item from the dropdownlist. I was already able to display the price on pageload but when I select a different item from the dropdownlist the price doesnt not change. The first items price is display on pageload.
<img src="http://social.microsoft.com/Forums/getfile/594/" alt="
codes are displayed below.
Populate the DDL using my own class:
<pre> public DropDownList populateProducts2(DropDownList ddl)
{
string select = "Select ProductName From ProductInfo";
adapter = new SqlDataAdapter(select, conString);
dt = new DataTable();
adapter.Fill(dt);
/*for (int i = 0; i < dt.Rows.Count; i++)
{
string productName = dt.Rows[0].ToString();
//string lastname = dt.Rows[1].ToString();
ddl.Items.Add(productName);
}*/
ddl.DataSource = dt;
ddl.DataTextField = "ProductName";
ddl.DataBind();
return ddl;
}[/code]
Page Load
<pre>protected void Page_Load(object sender, EventArgs e)
{
//sql.getOrder(GridView1);
sql.populateCustomer(DropDownList1);
sql.populateProducts2(DropDownList2);
textProdPrice.Text = sql.getProductPrice(DropDownList2.SelectedValue);
}[/code]
<br/>
To get the price
<pre> public string getProductPrice(string ProductName)
{
string select = "Select Price From ProductInfo where ProductName = "+ProductName+"";
adapter = new SqlDataAdapter(select, conString);
dt = new DataTable();
adapter.Fill(dt);
//for (int i = 0; i < dt.Rows.Count; i++)
//{
//string productName = dt.Rows[0].ToString();
//string lastname = dt.Rows[1].ToString();
//ddl.Items.Add(productName);
//}
string price = dt.Rows[0][0].ToString();
return price;
}[/code]
<hr class="sig Randel Ramirez
View the full article
item from the dropdownlist. I was already able to display the price on pageload but when I select a different item from the dropdownlist the price doesnt not change. The first items price is display on pageload.
<img src="http://social.microsoft.com/Forums/getfile/594/" alt="
codes are displayed below.
Populate the DDL using my own class:
<pre> public DropDownList populateProducts2(DropDownList ddl)
{
string select = "Select ProductName From ProductInfo";
adapter = new SqlDataAdapter(select, conString);
dt = new DataTable();
adapter.Fill(dt);
/*for (int i = 0; i < dt.Rows.Count; i++)
{
string productName = dt.Rows[0].ToString();
//string lastname = dt.Rows[1].ToString();
ddl.Items.Add(productName);
}*/
ddl.DataSource = dt;
ddl.DataTextField = "ProductName";
ddl.DataBind();
return ddl;
}[/code]
Page Load
<pre>protected void Page_Load(object sender, EventArgs e)
{
//sql.getOrder(GridView1);
sql.populateCustomer(DropDownList1);
sql.populateProducts2(DropDownList2);
textProdPrice.Text = sql.getProductPrice(DropDownList2.SelectedValue);
}[/code]
<br/>
To get the price
<pre> public string getProductPrice(string ProductName)
{
string select = "Select Price From ProductInfo where ProductName = "+ProductName+"";
adapter = new SqlDataAdapter(select, conString);
dt = new DataTable();
adapter.Fill(dt);
//for (int i = 0; i < dt.Rows.Count; i++)
//{
//string productName = dt.Rows[0].ToString();
//string lastname = dt.Rows[1].ToString();
//ddl.Items.Add(productName);
//}
string price = dt.Rows[0][0].ToString();
return price;
}[/code]
<hr class="sig Randel Ramirez
View the full article