Solved

Problems with autopostback listboxes, and duplicate values

Posted on 2004-10-07
8
345 Views
Last Modified: 2007-12-19
***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)
{
  if(!IsPostBack)
  {
    ListBoxSequence.DataSource = (ArrayList) Session["FileSequence"];
    ListBoxSequence.DataBind();
  }
}

***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?
0
Comment
Question by:yizchaknaveh
8 Comments
 
LVL 18

Expert Comment

by:tusharashah
ID: 12255450
Well you need to make sure that Value of SelectedItems are different, otherwise you'll this behavior is likely.

-tushar
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12255771
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.

John
0
 

Author Comment

by:yizchaknaveh
ID: 12260448
I have tried jhnorst's suggestion, but that still does not work.  Are there any workarounds/alternatives?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:yizchaknaveh
ID: 12260751
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.
0
 

Author Comment

by:yizchaknaveh
ID: 12277899
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.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12602240
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question