Solved

Problems with autopostback listboxes, and duplicate values

Posted on 2004-10-07
8
335 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now