Solved

Problems with autopostback listboxes, and duplicate values

Posted on 2004-10-07
8
341 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

16 Experts available now in Live!

Get 1:1 Help Now