M
Mehdi
Here is what you need to do to replicate the problem that I encountered...
Drag 'n drop a ListBox control into a Webform (ASP.Net 2003/2005
application). Then add a few items into the ListBox's Items collection using
the IDE or using aspx declarative syntax. Make some of the Values the same
(but different Texts). eg,
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="2">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
here, two items have the same value.
Now, put any code you want to check the SelectedIndex property of the
Listbox. You can simply add Response.Write(ListBox1.SelectedIndex) to the
SelectedIndexChanged event handler (with AutoPostBack="True").
Run the program.
Here is what happens... when you select any of the same-valued item the
SelectedIndex returned is always that of the first item of the same-valued
items. In our example, it will return 1 whether you select Item 2 or 3.
Even more interesting, if you did turn on AutoPostBack="True", then when you
select Item 3 it will jump back to Item 2 on postback.
(However, if you are curious, javascript does return the correct
selectedIndex.)
Is this a known issue or a bug with the Listbox webcontrol?
Drag 'n drop a ListBox control into a Webform (ASP.Net 2003/2005
application). Then add a few items into the ListBox's Items collection using
the IDE or using aspx declarative syntax. Make some of the Values the same
(but different Texts). eg,
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="2">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
here, two items have the same value.
Now, put any code you want to check the SelectedIndex property of the
Listbox. You can simply add Response.Write(ListBox1.SelectedIndex) to the
SelectedIndexChanged event handler (with AutoPostBack="True").
Run the program.
Here is what happens... when you select any of the same-valued item the
SelectedIndex returned is always that of the first item of the same-valued
items. In our example, it will return 1 whether you select Item 2 or 3.
Even more interesting, if you did turn on AutoPostBack="True", then when you
select Item 3 it will jump back to Item 2 on postback.
(However, if you are curious, javascript does return the correct
selectedIndex.)
Is this a known issue or a bug with the Listbox webcontrol?