Capture selected Dropdownlist item

Asked

Viewed 1,278 times

2

I have a DropDownList with some items, and I made a click event to pick up what is selected and redirect to a page, however not working right, see:

switch(ddlMenu.SelectedValue){

            case "0":
             lblMensagem.Text = "Por favor, selecione uma opção valida";
                break;

            case "1":
                Response.Redirect("/pages/cadastro.aspx");
                break;

                case "2":
                Response.Redirect("/pages/consultas.aspx");
                break;

                case "3":
                Response.Redirect("/pages/detalhes.aspx");
                break;


}

The problem is that it only works item 0, and item 1, item 2 and item 3 the result is like item 0.

Does anyone know why it’s wrong?

  • I spoke in the post, only works item 0, and item 1, 2 and 3 processes the message of 0, ie when selecting 2 or 3, it is entering the action of 0.

  • Only with this excerpt you can not see any problem, it is correct. Maybe not even 0 is being done but you are not realizing.

  • 1

    @Warlock does not mean ddlMenu.SelectedIndex and then do the switch at that value (0, 1, 2, 3)?

  • Have you debugged? And what’s coming in SelectedValue?

2 answers

1

The case is that, at the dropdownlist click, the selected value is still zero, for its value has not yet been changed.

Use the event SelectedIndexChanged(), this will be triggered after the dropdownlist value is changed.

1

See how you’re carrying the ddlMenu utilize.

int32 idMenu=  ddlMenu.SelectedId();

and then do the switch case , probably your mistake is in the way you are carrying the DropDownList .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.