Reputation: 1
I'm trying to create an If statement for a dropdown list on visual studio. When selecting a value in the list I would like it to show on its own once selected, although all values in the list are being outputted. Below is the code I'm using:
protected void btnCalculate_Click(object sender, EventArgs e)
{
//Declare Variables
String strFrance;
String strPortugal;
String strItaly;
String strSpain;
String strAmsterdam;
String strPoland;
//Assign Values
strFrance = "300";
strPortugal = "350";
strItaly = "400";
strSpain = "400";
strAmsterdam = "250";
strPoland = "350";
if (lstPackages.SelectedItem.Text == "France") ;
{
Response.Write("The Price of France is" + strFrance + "<br />");
}
if (lstPackages.SelectedItem.Text == "Portugal") ;
{
Response.Write("The Price of Portugal is" + strPortugal + "<br />");
}
if (lstPackages.SelectedItem.Text == "Italy") ;
{
Response.Write("The Price of Italy is" + strItaly + "<br />");
}
if (lstPackages.SelectedItem.Text == "Spain") ;
{
Response.Write("The Price of Spain is" + strSpain + "<br />");
}
if (lstPackages.SelectedItem.Text == "Amsterdam") ;
{
Response.Write("The Price of Amsterdam is" + strAmsterdam + "<br />");
}
if (lstPackages.SelectedItem.Text == "Poland") ;
{
Response.Write("The Price of Poland is" + strPoland + "<br />");
}
Upvotes: 0
Views: 537
Reputation: 17382
remove the ;
after the if (lstPackages.SelectedItem.Text == "...") ;
Ie
if (lstPackages.SelectedItem.Text == "France")
{
Response.Write("The Price of France is" + strFrance + "<br />");
}
instead of
if (lstPackages.SelectedItem.Text == "France") ;
{
Response.Write("The Price of France is" + strFrance + "<br />");
}
If you hover over the ;
in Visual Stuido you will see a warning ..
BTW: You can assign a value directly at creation of a variable. Ie
string strFrance = "300";
Upvotes: 2