如何从下拉值中执行标签值的乘法运算,然后将其重新放入dt标签中 [英] how to perform multiplication of a labels value from dropdown value and then put it back in to dt label

查看:81
本文介绍了如何从下拉值中执行标签值的乘法运算,然后将其重新放入dt标签中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var price = from st in obj.movie_details
                    where st.Id == name
                    select st.price;
        int? myPrice = price.FirstOrDefault();
        Int32 pricein = myPrice.HasValue ? myPrice.Value : 0;
        Label2.Text = pricein.ToString();



这是查询,值在label2

,这里是下拉菜单


this is the query and the value is in label2
and here is a dropdown

<asp:DropDownList ID="DropDownList1" runat="server" 

                onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                <asp:ListItem>1
                <asp:ListItem>2
                <asp:ListItem>3
                <asp:ListItem>4
                <asp:ListItem>5
                <asp:ListItem>6



现在我希望我选择下拉值,该值应该与label2s值相乘,现在再次将此值放在label2中


now i want that as i m select the value of dropdown that should be multiply by the label2s value and now put this value again in label2

推荐答案

这样:

This way:
private void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
   int factor = DropDownList1.SelectedIndex + 1;
   int pricein = int.Parse(Label2.Text);
   int totalPrice = pricein * factor;
   Label2.Text = totalPrice.ToString();
}





但是:如果您多次更改DropDownList中的选项,则Label中的值将每次增加。

您应该不依赖于标签显示的值,而是依赖于您可以从EventHandler访问的类中存储的整数变量。





BUT: if you change the selection in the DropDownList several times, the value in your Label will increase each time.
You should rely not on the value displayed by the label, but on an integer variable stored in your class that you can access from the EventHandler.

private void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
   int factor = DropDownList1.SelectedIndex + 1;
   int totalPrice = pricein * factor; // Here pricein has to be declared outside the method and must hold the unbiased price value
   Label2.Text = totalPrice.ToString();
}





希望这会有所帮助。



Hope this helps.


这篇关于如何从下拉值中执行标签值的乘法运算,然后将其重新放入dt标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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