Hi ive got a drop down list where a qty of items can be selected. 1-8.
For each item as an example if they buy one they get 25% off. if they buy 2 they get 30% 3 35%, (so it goes up 5% each time they purchase an item.
What would be an easier way to do this? mine seems quite tedious. Can you provide an exaple code please.
This is what i have but i would have to do many if statements.
protected void Page_Load(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "1")
{
int test = Convert.ToInt32(DropDownList1.SelectedValue);
TextBox1.Text = Convert.ToString(test * (199 * (1 - 0.25)));
}
else if (DropDownList1.SelectedValue == "2")
{
int test = Convert.ToInt32(DropDownList1.SelectedValue);
TextBox1.Text = Convert.ToString(test * (199 * (1 - 0.30)));
}
else if (DropDownList1.SelectedValue == "3")
{
int test = Convert.ToInt32(DropDownList1.SelectedValue);
TextBox1.Text = Convert.ToString(test * (199 * (1 - 0.35)));
}
}
You should work on Selected Index. Because it gives a number.
Multiply that number with
0.05 (0.35 -0.30 = 0.05, 0.30-0.25 = 0.05)and add in0.25Let’s say
Selected Indexis0then(0 * 0.05) + 0.25 = 0.25If its
1then(1 * 0.05) + 0.25 = 0.30and so on….