Solved

Problems with autopostback listboxes, and duplicate values

Posted on 2004-10-07
8
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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