I am trying to calculate a value when a item of a drop down list is selected. I am trying to do this using a switch but it doesn't work. It always goes to the default value and it doesn't see a value of a variable.
I'm building my drop down list dynamic from my database.
This is the code I have so far:
protected void ddlClub_SelectedIndexChanged(object sender, EventArgs e)
{
// INSCHRIJFGELD BEREKENEN
// variabelen voor berekenen inschrijfgeld
double club1Price;
club1Price = 1.25;
double club2Price;
club2Price = 5.50;
double club3Price;
club3Price = 9.25;
double price;
price = 20.00;
int value;
value = Convert.ToInt16(ddlClass.SelectedValue.ToString());
switch (ddlClub.SelectedItem.Text)
{
case "club 1":
if (Double.TryParse(lblAmount.Text, out club1Price))
club1Total = club1Price * value;
string totalRoundClub2 = Convert.ToString(Math.Round(club2Total, 2, MidpointRounding.AwayFromZero));
lblAmount.Text = Convert.ToString(totalRoundClub2);
break;
case "club 2":
if (Double.TryParse(lblAmount.Text, out club2Price))
culb2Total = club2Price * value;
string totalRoundClub2 = Convert.ToString(Math.Round(club2Total, 2, MidpointRounding.AwayFromZero));
lblAmount.Text = Convert.ToString(totalRoundClub2);
break;
case "club 3":
if (Double.TryParse(lblAmount.Text, out club3Price))
club3Total = club3Price * value;
string totalRoundClub3 = Convert.ToString(Math.Round(club3Total, 2, MidpointRounding.AwayFromZero));
lblAmount.Text = Convert.ToString(totalRoundClub3);
break;
default:
if (Double.TryParse(lblAmount.Text, out price))
total = price * value;
string totalRound = Convert.ToString(Math.Round(total, 2, MidpointRounding.AwayFromZero));
lblAmount.Text = Convert.ToString(totalRound);
break;
}
}
The variables in my class:
public partial class Inschrijven : System.Web.UI.Page
{
double club1Total;
double club2Total;
double club3Total;
double total;
Can someone please help me?
Thanks in advance!