Solved

Listbox - Multiselect - Best Practices / Examples

Posted on 2004-09-16
3
503 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
  • 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 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Contant UI messages in .NET 1 40
What are the big features of MVC5? 4 50
Editing XSL files, 2 21
dynamic menu in asp.net c# 11 26
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

12 Experts available now in Live!

Get 1:1 Help Now