如何根据下拉列表中的值选择重定向页面?
这是我的C#代码。在该代码中,在下拉列表中有3个值断裂,关节和骨质疏松症。根据值的选择,它将相应地打开该页面并插入数据库。但在我的编码中,如果我选择破裂,它将不会重定向到该页面,而是插入数据库中,而当我选择关节和骨质疏松症值时,它将重定向到该页面但不会插入数据库中。任何人都可以告诉我我犯的错误,请提供适当的解决方案 ????
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 ????
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
如果下拉列表中有选择,如果它放在第零索引上,那么它将不会重定向
尝试像这样给出选定的值...
if dropdown having "Select" and if it it placed on Zeroth Index then it will not Redirect
Try to Give Selected Value like this...
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";
}
}