我想显示所选下拉列表项的价格。 [英] i want to show price of selected dropdownlist item.
问题描述
我做了两个下拉菜单和一个标签。
1.ddCategory下拉菜单
2.ddProduct下拉菜单
3.价格优惠
i hvae数据库中有3个表。第一个是CategoryData第二个是ProductData,第三个是PriceData
CAtegoryData数据绑定到ddCategory //(Id,CAtegory_Id,Name)4个类别
ProductData数据绑定到ddProduct //((Id,Category_Id,Product_Name)8每个类别中的产品
Pricedata有价格。(Id,Category_Id,Price)
用户选择类别。产品显示所选类别。然后价格应显示在标签上。
i无法显示价格进入标签。
i猜我的选择声明错了。
这里的代码,请尽快帮助
i made two dropdowns and 1 lable.
1.ddCategory dropdown
2.ddProduct dropdown
3.Price lable
i hvae 3 tables in database. 1st is CategoryData 2nd is ProductData and 3rd is is PriceData
CAtegoryData is databound to ddCategory // (Id,CAtegory_Id,Name)4 categories
ProductData is databound to ddProduct // ((Id,Category_Id,Product_Name)8 Product in each category
Pricedata has price. (Id,Category_Id,Price)
user select category. product are shown of the selected category. and then the price should be displayed on the lable.
i just couldn't display price into the lable.
i guess my select statement is wrong.
code here, please help asap
SqlCommand cmd = new SqlCommand("Select * From PriceData Where Id ='" + ddCategory.SelectedValue + "'", con);
cmd.Parameters.AddWithValue("@Price", ddProduct.SelectedItem.Value);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
Price.Text = sdr["Price"].ToString();
}
推荐答案
这可以解决您的问题。
This should resolve your problem.
SqlCommand cmd = new SqlCommand("Select * From PriceData Where Id =" + ddProduct.SelectedValue.ToString(), con);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
string price = cmd.ExecuteScalar();
if (!price.Equals(String.Empty))
{
Price.Text = price;
}
假设:
PriceData表在字段Id中存储productid
如果这不能解决问题,请告诉我!
Assumption:
PriceData table is storing productid in the field Id
In case this doesn't resolve the issue, please let me know !
这篇关于我想显示所选下拉列表项的价格。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!