?
Solved

Listbox - Multiselect - Best Practices / Examples

Posted on 2004-09-16
3
Medium Priority
?
514 Views
Last Modified: 2006-11-17
I have a general question concerning insertion of multi-selected items from a listbox - specifically as to the best method to identify the multiple selections and what the best method to store them in a SQL table (via CSV string or in a separate / dedicated table, etc.)?  Examples would be greatly appreciated!!!  Additionally, would be interested in how I can retrieve the results from the SQL db and set the selected values in a Listbox, within a Datalist - any help would be greatly appreciated!!!!!!
0
Comment
Question by:tbaseflug
[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
  • 2
3 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 12076645
As far as identifying selections, just iterate through the listitems of the listbox on postback, and get the selections, there is really no easier way.

Storing the data is a little bit more tricky, let me try to steer you from making a mistake.  Realize if you store their selections in a csv form you break the first rule of normalization in table design.  Ideally you'd want a separate table for selections that relates to the primary table.  When it comes to updating their selections, I'd first delete all the old ones, and insert a record for each of their new selections.

If you do it like this, here is where it is a bit easier, updating their selections back to the listbox.  You can design a sql query to outer join two tables (all the items you want in the listbox, and the selected items they have chosen), that way you'll know if they are selected or not, then instead of setting datasource/databind, add the items manually to the listbox, and if from the query you can determine that they were selected, add the listitem as selected.  Make sense?

--Michael
0
 

Author Comment

by:tbaseflug
ID: 12077009
raterus -

That does make sense - is there any way that you could provide an expample on how to ("add the items manually to the listbox") - assuming that the values will bve coming from a sproc?
0
 
LVL 33

Accepted Solution

by:
raterus earned 2000 total points
ID: 12077513
Well it really doesn't matter where they come from, once you get them simply iterate through them and do something like this. (using a SqlDataReader)

while rdr.read()
  Dim li as listitem = new listitem
  li.text = rdr("textfield")
  li.value = rdr("valuefield")
  if cbool(rdr("selected") = true then
    li.selected = true
  end if

  myListBox.Items.Add(li)
End while

This is assuming you've correctly created a result set that already has "selected" if they selected it or not.

--Michael

0

Featured Post

Independent Software Vendors: 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

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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

800 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