Dropdown list

I discover what appears to be a bug with the dropdownlist control.

I create a dropdown list containig items and grouped bys sections like this :



Of course using a server side control. Everything fine, but the problems are in the code.

The control is bind with some data. Each of the subtitle contains a null value, and the Topic items contains their own id.
I use an event on the onchange of the select control. when the event is fired, I use the selectedindex property to detect if I select a subtitle (just there for decoration), or a topic.

For the Topic, no problem, everything is ok, but for the subtitle, what I wanted is to select the next Topic automatically after the subtitle.
For example, if I select Energy I want to go tot the Topic 1, or if I choose the line over Energy, I jump to Topic1.

Piece of cake? Not exactly because whatever I tried so far, the selectedindex of my elements were back with a value of 0 or 1, if I didn't choose a Topic.
Pushing further my tests, I discover what seem to be the origin of the problem.
If you don't have any value in a item in a dropdownlist, the selectedindex is always the first element matching the search.
I don't remember this kind of behavior before with ASP and Javascript.

For me selectedindex should return an integer, whatever the value of the item.

So for me the solution was to include some dummy unique values for each of the Subtitles in my dropdown control, and using indexof, to make the difference between different items.

No Comments