Problems with Selectedindexchanged Asp.net C#

Asked

Viewed 460 times

2

I added it in the method where you load the list from the bank:

ddlSalas.Items.Insert(0, new ListItem("TODAS", ""));

When I choose this "ALL" option on dropdownlist, happens a post on the page but it does not call the event selectedindexchanged which contains the method that will load a gridview with the information.

What could be going on? What I did wrong ?

2 answers

2

Well strange guy, it was supposed to work, if the generated of your file correctly generated the assignment of the event to your dropdownlist, but beauty, to ensure that your method is called, try to put after adding the items in the list this command:

dropdownlist.SelectedIndexChanged += new EventHandler(dropdownlist_SelectedIndexChanged);
  • Same thing @Thiago Falcão, when running, I choose the option and a post happens on the page but does not return anything and neither calls the breakpoint. When I select another one (which in the case is returning from the bank) it works, and after I chose an option that worked, I go back to it and it works.

  • @Andreeh po cara, I think it should be getting lost in the index so, it seems that this first value is with negative index, try to see the Indice when you select the other items that enter the event, more or less so you will know which index is: switch (dropdownlist.Selectedindex) { case 1: // ..... some code here... break; case 2: // ..... some code here... break; case 3: // ..... some code here... break; default: // ..... some code here... break; }

  • Beauty @Thiago Falcão. I’ll try.

1


What is the initial data of the combo ? is already the All ? How about using a ddlSalas.Items.Insert(-1, new Listitem("Select", "")); before ddlSalas.Items.Insert(0, new Listitem("ALL", "")); ? Will it work ?

  • I managed to sort it out. Thank you.

  • it would be nice if you post the solution so everyone knows how to solve !

  • I was doing wrong, I was passing empty and it did not fall even at the breakpoint, then the solution was to assign a value "0" and change the query in the Procedure to return the records according to the passage "0" ddlSalas.Items.Insert(1, new Listitem("ALL", "0"));

Browser other questions tagged

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