Capture selected DropDownList item

2

I have DropDownList with some items, and I did a click event to get what is selected and redirect to a page, but it is 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 only works item 0, and item 1, 2 and 3 the result is as if it were item 0.

Does anyone know why it's wrong?

    
asked by anonymous 05.02.2015 / 03:30

2 answers

1

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

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

    
06.01.2016 / 17:51
1

See how you are loading ddlMenu .

int32 idMenu=  ddlMenu.SelectedId();

Then switch switch case , probably your error is in the form you are loading DropDownList .

    
23.10.2015 / 17:52