question

HemanthB-9452 avatar image
0 Votes"
HemanthB-9452 asked HemanthB-9452 commented

Going to a specific link on dropdown list item selection - ASP.NET WebForms

Hi, I added a drop down list in web forms asp.net c#. I double clicked and added this code. Selecting "Length Calculator" should redirect them to another web form. But when I test it, it's not working. But the "Response.Redirect" code works for a button perfectly. Pls help!

   protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
         {
             if (DropDownList1.SelectedValue == "Length Calculator")
             {
                 Response.Redirect("Length Converter.aspx");
             }
         }

Image for the dropdown list items108942-sss.png


dotnet-aspnet-webpages
sss.png (8.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered HemanthB-9452 commented

Hi @HemanthB-9452 ,
I suggest you could check if you run the method of SelectedIndexChanged. Do you have add AutoPostBack="true" in the dropdownlist?
I have created a test and it works.Just like this:

  <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
                 <asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
                 <asp:ListItem Value="Length Calculator" Text="Length Calculator"></asp:ListItem>
             </asp:DropDownList>

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
         {
             if (DropDownList1.SelectedValue == "Length Calculator")
             {
                 Response.Redirect("2175764.aspx");
             }
         }


Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks so much! It worked.

0 Votes 0 ·