I have a scenario that my DropDownList is dynamically populated by the end user. But, sometimes, two or more items can have the same value. For example:
<asp:DropDownList runat="server" ID="ddl" AutoPostBack="true">
<asp:ListItem Text="Item 1" Value="Item 1" />
<asp:ListItem Text="Item 2" Value="Item 2" />
<asp:ListItem Text="Item 3" Value="Item 2" />
</asp:DropDownList>
When I select the third item, ASP.NET selects the second one during the page refresh, because both have the same value. So, it does not use the selected index, but the selected value. Is there a way to change this behavior on my application?
I add all the controls dynamically, so it would be nice if I could have an elegant way of doing this automatically for each control that I add to the web page. Any suggestions?
Update 1:
Added a sample project to github: https://github.com/vmrocha/dropdown-issue