在下拉菜单中更新标签 [英] Updating Label on dropdown selection

查看:128
本文介绍了在下拉菜单中更新标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试制作一个订购单,一旦用户从下拉列表中选择一个项目,标签就会自动填充用户的选择.
假设用户从下拉菜单中选择项目,然后为该项目添加标签填充率

给我一个例子..

谢谢

Hi,
I''m trying to make a order form where once the user selects an item from the drop down list, the label will automatically be populated with the user''s selection.
suppose user select item from drop down then label populate rate for that item

give me a sample example..

Thanks

推荐答案

好,因为您必须在下拉列表中选择代码更改和
编写代码 将其autopostback属性设为true;
然后将代码写为
SqlCommand cmd =新的SqlCommand(从tableme中选择* where item = @ item",con);
con.Open();
cmd.Parameters.AddWithValue("@ item",dropdown.selectedvalue);

SqlDataReader dtr = cmd.ExecuteReader();
如果(dtr.Read())
{
Label1.Text = dtr ["Rate"].Tostring();
dtr.Close();
con.Close();

}
其他
{

Label1.Text =没有价格";
dtr.Close();
con.Close();

}
Ok for that u will have to write code on dropdown selected index changing and
make its autopostback property true;
and write code as
SqlCommand cmd = new SqlCommand("select * from tableme where item=@item ", con);
con.Open();
cmd.Parameters.AddWithValue("@item ", dropdown.selectedvalue );

SqlDataReader dtr = cmd.ExecuteReader();
if (dtr.Read())
{
Label1.Text=dtr["Rate"].Tostring();
dtr.Close();
con.Close();

}
else
{

Label1.Text = "No Price is there";
dtr.Close();
con.Close();

}


这篇关于在下拉菜单中更新标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆