Problems with autopostback listboxes, and duplicate values

***I have the following ListBox with AutoPostBack turned on:

<asp:listbox id="ListBoxSequence" runat="server" Width="100%" Height="150px" CssClass="griditem" AutoPostBack="True"></asp:listbox>

***The list binds to a datasource as follows:

private void Page_Load(object sender, System.EventArgs e)
    ListBoxSequence.DataSource = (ArrayList) Session["FileSequence"];

***The ArrayList that the ListBox binds to contains duplicate values.  My problem is this - when one clicks on a duplicate value, the SelectedItemIndex returned is that of the _first_ instance of the duplicate value, not the correct instance.  So, if I have the following ArrayList - {"bob", "sue", "bob"} and I click on the third entry, the SelectedItemIndex is 0.

What am I doing wrong?
Who is Participating?
moduloConnect With a Mentor Commented:
PAQed with points refunded (500)

Community Support Moderator
Well you need to make sure that Value of SelectedItems are different, otherwise you'll this behavior is likely.

The Items collection of the drop down list is, I think, a ListItemCollection class.  You might want to create a ListItemCollection class independent of the ddl.  Populate it and put it Session state and the bind to it.

The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

yizchaknavehAuthor Commented:
I have tried jhnorst's suggestion, but that still does not work.  Are there any workarounds/alternatives?
yizchaknavehAuthor Commented:
I should mention that the ListItemCollection seems to be OK ({"bob", "sue", "bob"}).  It's just that for some reason, the SelectedItemIndex always points to the first instance of a value.
yizchaknavehAuthor Commented:
In case anyone is interested, I came up with my own solution by capturing the onClick() event with JavaScript and forcing a postback with the selection transferred as a hidden field.  Nothing else worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.