Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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();

this is the query and the value is in label2
and here is a dropdown
ASP.NET
<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

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
Posted
Updated 9-Sep-13 20:48pm
v3

1 solution

This way:
C#
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();
}


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.

C#
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.
 
Share this answer
 
v3
Comments
Omprakash Kukana 10-Sep-13 3:27am    
but mr phil.o my label2s value is not updaing on change in dropdown
Omprakash Kukana 10-Sep-13 3:44am    
here is an error is generating dt the name pricein does not exist in current context
how to declre ds pricein
Omprakash Kukana 10-Sep-13 4:11am    
10nx mr phil.o its working better

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900