ITsolutionWizard
asked on
c#, case, if
Below codes in c#. how can I use CASE instead?
The goal is to shorten the codes....
Thanks
The goal is to shorten the codes....
Thanks
DropDownList selectedInsuranceProductType = (DropDownList)InsuranceTypesList.FindControl("insuranceProductsList");
if (selectedInsuranceProductType.SelectedValue == "Health")
{
panelHealth.Visible = true;
}
else if (selectedInsuranceProductType.SelectedValue == "Life")
{
panelLife.Visible = true;
}
else if (selectedInsuranceProductType.SelectedValue == "Accident")
{
panelAccident.Visible = true;
}
else if (selectedInsuranceProductType.SelectedValue == "Dental")
{
panelDental.Visible = true;
}
else
{
panelHealth.Visible = false;
panelLife.Visible = false;
}
ASKER
missing below
else
{
panelHealth.Visible = false;
panelLife.Visible = false;
}
else
{
panelHealth.Visible = false;
panelLife.Visible = false;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Furthermore one of the commandments states that "Thou shalt not access object properties often".
If we are to abide by it:
If we are to abide by it:
String insuranceProductType = selectedInsuranceProductType.SelectedValue;
panelHealth.Visible = insuranceProductType == "Health";
panelLife.Visible = insuranceProductType == "Life";
panelAccident.Visible = insuranceProductType == "Accident";
panelDental.Visible = insuranceProductType == "Dental";
Open in new window