473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ListBox and DataSource help

3
Hello,

I am writing a page (C#) that uses one ListBox that retrieves data from a DB using SqlDataSource and the SelectCommand.
Expand|Select|Wrap|Line Numbers
  1. <asp:SqlDataSource ID="DataSource1" SelectCommandType=Text runat="server" ConnectionString="<%$ ConnectionStrings:SQLDB %>" />
  2. <asp:ListBox ID="ListBox1" runat="server" SelectionMode=Single Rows=20 Width="250px" DataSourceID="DataSource1" >
  3.  
The Listbox populates fine and also retrieves values fine. I put a button under it that, when pressed, uses the Text of the selected item in this ListBox to query the DB using another SelectCommand of a separate SqlDataSource to retrieve other data and place it in a second ListBox so it is dynamically updated while maintaining the original items in the original ListBox.

My problem is when I select an item in the second ListBox and attempt to retrieve the data, it always brings the selection to the first one in the list, and making the data I am trying to retrieve set to the first item. Upon doing some searching and debugging, I found that the problem seems to be in updating the SqlDataSource.SelectCommand. It seems that when I update it, it repopulates the ListBox correctly but doing anything that causes any type of page loading or interaction causes the selection to either go to index 0 (after ListBox2 repopulates) or jump around (before it gets repopulated).

Any help, advice, or workarounds would be greatly appreciated.
Jul 18 '08 #1
2 3868
kenobewan
4,871 Expert 4TB
You can have more than one datasource per control. Sounds like you need to control the order of events and/or postbacks in the code behind. HTH.
Jul 20 '08 #2
Phijo
3
You can have more than one datasource per control. Sounds like you need to control the order of events and/or postbacks in the code behind. HTH.
How would I control the order of events if I want the list to be dynamically updated? Is there a command that causes it to reload with the new DataSource? If there is something wrong with the order things are being executed, then why is the list being populated with the correct items?

I tried editing my code so that now I have:
Expand|Select|Wrap|Line Numbers
  1. AutoPostBack=true OnSelectedIndexChanged="SelectItem"
  2.  
However, it does the exact same thing as before where it only reports the first item in the selection. After changing the "SqlDataSource.SelectCommand" I can output it to an "asp:GridView" and it dynamically updates perfectly fine every single time I select something from the first (and second) "asp:ListBox".

I'm not exactly sure what needs to be done to fix this problem. Perhaps I am not understanding how some of these items work?
Jul 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Luca | last post by:
Hello, I'm using a windows form in which there is a standard ListBox control. I want to add/remove objects from the ArrayList associated to the ListBox, and I want the ListBox immediately shows...
3
by: Prasad | last post by:
Hey All, I am having a little trouble with the ListBox's Items collection property. I am populating the ListBox with data contained in an SQL table using SQLDataAdapter and DataSet. I have...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
0
by: David J | last post by:
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem...
13
by: Larry Woods | last post by:
I am creating a "from-to" set of listboxes where the "left" listbox had a list of values and I want to be able to select these values, 1 at a time, and move them into a "right" listbox, removing...
11
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
1
by: sklett | last post by:
I've setup the simplest of tests; A form with a ListBox and a Button. The ListBox is bound to a List<string>. When you click the Button, a new string is added to the list. I can't for the life...
1
by: Refugnic | last post by:
I tried to fill a ListBox with a DataSource pointing to an ArrayList. It all works fine...up to one point. The ArrayList is dynamic, which means the contents of it change, during the course of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.