Datalist - Listbox: Parse CSV string/value and pre-select multiple items

Posted on 2004-09-09
Last Modified: 2008-03-17
I have a listbox and am allowing the user to make multiple selections from it - the selected values are combined and concatenated via the below code and then insterted into a single SQL column.  

        Dim str3() As String
        Dim strHardware As String
        For i As Integer = 0 To lbServersHardwareAffected.Items.Count - 1
            If lbServersHardwareAffected.Items(i).Selected = True Then
                strHardware = strHardware + lbServersHardwareAffected.Items(i).Text
                strHardware = strHardware + ", "
            End If
        If Not strHardware = "" Then
            strHardware = Left(strHardware, Len(strHardware) - 2)
        End If
        str3 = strHardware.Split(CType(",", Char))

What I am trying to do is to grab the results from the SQl column (e.g. = value1, value2, value3) and setup a listbox in a datalist to pre-select the values.  I am using a Dataset and a store rpocedure to select and return the data from the database.  Need it in VB.NET if possible -
Question by:tbaseflug
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
  • 4
  • 3
LVL 17

Expert Comment

ID: 12021234
what are you doing after you split them, how are they stored in your db field?

Author Comment

ID: 12021283
They are actually combined and then stored in the db field as:

value1, value2, value3

What I need to do is split them from the db
LVL 17

Expert Comment

ID: 12021329
I use this to split csv from my sql server for a csv of users:

HttpContext.Current.User = New GenericPrincipal(User.Identity, Split(authTicket.UserData, ","))
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!


Author Comment

ID: 12021357
Any idea how I would set the selections to a listbox to from something like that?
LVL 17

Accepted Solution

AerosSaga earned 500 total points
ID: 12021368
Once you have them to strings insert them like this:

ddl.Items.Insert(0, MyStringVariable);

Author Comment

ID: 12027063
Let me give it a shot and will let you know as soon as I am done - thanks!!!!

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL ( and MongoDB (…
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…

696 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