2
Answers

Problem with RadioButtonList

Nel

Nel

9y
662
1

Hi,

Hi,

I have a radioButtonList with two ites. If one of them is checked one formula should be implemented in the code, or if the other button is checked a second formula should be implemented.

Here is my code:

protected void Page_Load(object sender, EventArgs e)
        {           

            if (RadioButtonList1.SelectedIndex !=0 && RadioButtonList1.SelectedIndex!=1)
            {
                Response.Write("Please select a formula");
            }

            else if (RadioButtonList1.SelectedIndex > -1)
            {
                Response.Write(RadioButtonList1.SelectedValue+RadioButtonList1.SelectedIndex);
            }

            if (!Page.IsPostBack)
            {
                if (RadioButtonList1.SelectedIndex > -1)
                {
                    Response.Write(RadioButtonList1.SelectedValue);
                }
.....
............

 private void Calculation()
        {
            double a, b, TravTime,  DefFF, FreeTravTime, delayHere, TTvalue;
            double vc = 0.0;
            a = double.Parse(aBox.Text);
            b = double.Parse(bBox.Text);
            TravTime = double.Parse(list2[i]);
            FreeTravTime = double.Parse(fftimes[firstff]);

            if (selectedFormula == "BPR formula")//RadioButtonList1.SelectedIndex==0
            {
               .......
                    vc = Math.Pow(((TTvalue / DefFF) - 1) / a, 1 / b);
                .....
            }
            else if (selectedFormula == "FAU formula")//RadioButtonList1.SelectedIndex==1
            {
                ........
                vc = (Math.Log((TravTime / FreeTravTime) * (1 / a))) / b;
            }

but if I put the if statements it doesn't calculate correctly, and if I comment

  //if (selectedFormula == "BPR formula")//RadioButtonList1.SelectedIndex==0
            //{
            //   .......


                    vc = Math.Pow(((TTvalue / DefFF) - 1) / a, 1 / b);


           // }
           // else if (selectedFormula == "FAU formula")//RadioButtonList1.SelectedIndex==1
           // {
           //     ........
           //     vc = (Math.Log((TravTime / FreeTravTime) * (1 / a))) / b;
           // }

it works

Can anybody help me why when checking a different radiobutton, it doesn't work, as if nothing happened?

I also added the method:


  protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (RadioButtonList1.SelectedIndex ==0)
            {
                Response.Write(RadioButtonList1.SelectedValue + RadioButtonList1.SelectedIndex);
                selectedFormula = "BPR formula";
            }
            else
            {
                Response.Write(RadioButtonList1.SelectedValue);
                selectedFormula = "FAU formula";
            }
        }

and it doesn't help

Can anybody help me please?
Thanks



Answers (2)