Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here, is my C# code. In that code, in dropdown list there are 3 values fracture,joints and osteoporosis. based on selection of values it will open that page accordingly with insertion in database. But in my coding if I select "fracture" it will not redirect to that page but insert in database and while when I select joint and osteoporosis value it will redirect to that page but not insert in database. Can anyone tell me the mistake which I was commiting and please provide the appropriate solution ????

C#
protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
    {
       // Response.Redirect("Orthodiagonsis.aspx?Value=" + DropDownList1.SelectedValue);
        if (DropDownList1.SelectedIndex == 0)
        {
            Response.Redirect("fracture.aspx");
        }
        else if (DropDownList1.SelectedIndex == 1)
        {
            Response.Redirect("Osteoporosis.aspx");
        }
        else if (DropDownList1.SelectedIndex == 2)
        {
            Response.Redirect("joints.aspx");
        }
        else
        {
            lbldmsg.Text = "Can't Redirect";
        }

    }


code block added
Posted
Updated 5-Apr-14 10:49am
v3
Comments
Homero Rivera 5-Apr-14 16:42pm    
This code has no commands to insert into the database. Probably, the code to insert into the database is in the Page_Load method of each destination page. You should probably look into that.

1 solution

if dropdown having "Select" and if it it placed on Zeroth Index then it will not Redirect
Try to Give Selected Value like this...

C#
protected void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
    {
       // Response.Redirect("Orthodiagonsis.aspx?Value=" + DropDownList1.SelectedValue);
        if (DropDownList1.SelectedValue == "F")
        {
            Response.Redirect("fracture.aspx");
        }
        else if (DropDownList1.SelectedValue =="O")
        {
            Response.Redirect("Osteoporosis.aspx");
        }
        else if (DropDownList1.SelectedValue =="J")
        {
            Response.Redirect("joints.aspx");
        }
        else
        {
            lbldmsg.Text = "Can't Redirect";
        }
 
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900