Multiple-Select Listbox only returns first selected value (and I'm not using SelectedItem...)

I'm looping through the items of a listbox, as you can see I'm raising a custom event, passing the selected values with custom event args up...

What happens however, is that only the first item will be tagged as being selected, no matter how many listbox items I select with control. Ie If I select "Transducer, Pressure Transmitter, Pressure & Temperature" the following is returned: 

Transducer is selected;
Pressure transmitter is not selected;
Pressure & Temperature is not selected;

I encoded the ampersand & so do not worry about string concat. This is the code: 

       Protected Sub btnCommit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim tempString As String
            Dim item As ListItem

            For Each item In lbKeywords.Items
                If item.Selected Then
                    tempString = tempString & item.Value & " is selected;"
                    tempString = tempString & item.Value & " is not selected;"
                End If
                'ce.Values = ce.Values & "debugcycle" & ";"
            Dim ce As New CommitEventArgs(tempString)

            RaiseEvent OnCommitted(Me, ce)
        End Sub

4/29/2008 12:43:23 PM 93655 articles. 6 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 21

 Hi try this code..

    Dim tempstring as string
    Dim i As Integer
    For i = 0 To (lbKeywords.Items.Count - 1)
       If (lbKeywords.Items(i).Selected) Then
              tempstring +=lbKeywords.Items(i).Value & ","
       End If

In tempstring variable,now u get the selected items of the ListBox.
I hope this helps..

You can't do everything...
But you can do something...
So never refuse to do something that you can.....
4/29/2008 1:00:06 PM


following code works for me...

 Protected Sub btnCommit_Click(ByVal sender As Object, ByVal e As System.EventArgs)   

    Dim tempString As String = ""   

    For Each item As ListItem In lbKeywords.Items

        If item.Selected Then

            tempString = tempString + item.Value + " is selected;"


            tempString = tempString + item.Value + " is not selected;"

          'ce.Values = ce.Values & "debugcycle" & ";"

       End If



  ' CommitEventArgs ce = new CommitEventArgs(tempString); 

  ' if (OnCommitted != null) {

  ' OnCommitted(this, ce);

    ' }   

End Sub


4/29/2008 1:02:32 PM

Similar Artilces:

On selecting value in second listbox. selected value in first textbox is lost
     Hello all, In a webapplication , I have to store the selected values in hidden fields with following code  <INPUT type="hidden" name="hidPatient" value=""> <INPUT type="hidden" name="hidPatientStatus" value="">  when i select the value in any list box following javascript function is called with this code   Response.Write "<SELECT id=" & strSelName & " name=" & strSelName & " validation=" & strValidation & " ...

Edit form with multiple value listbox
I have an edit form with a multiple value listbox. (Editing a previous created record.) If I change the selected value it appears to change on the edit form but when you debug it doesn't reconize and changes to the selected and returns the same selected I started with. The selected values are stored in array field ie: (010001) 01 = True & 00 = False <%@ Page Language="VB" EnableViewState="false" AutoEventWireup="false" CodeFile="Edit.aspx.vb" Inherits="Edit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Trans...

Using selected values from a Multi Select Listbox in a SQL query
I have seen a few post concerning this but don't really understand fully as I am new to this.  I would appreciate any help 1) First I loop through the Listbox control and get the selected values: Dim li As ListItemFor Each li In lbPClass.Items If li.Selected = True Then strPC += li.Value & ", " End If Next Label5.Text = strPC The resulting string looks something like: 101, 102, 100 ,    I get rid of the last space and "," with the following statement Label6.Text = Left(Label5.Text, Trim(Len(Label5.Text) - 2)) 2) I would then like to ...

How to use Select case statement to select web form controls
Hi; I don't know why I can't conceptionalize  this but I want to take these if statements and put them in a select case. I am testing for multiple selection from several DDLs on my web form.   If DropDownList1.SelectedIndex > -1 And DropDownList2.SelectedIndex > 0 Then If Me.CheckBox1.Checked Then ObjectDataSource1.FilterExpression = "assignee = {0} AND assignor = {1}" Else ObjectDataSource5.FilterExpression = "assignee = {0} AND assignor = {1}" End If End If If DropDownList1.SelectedIndex > -1 And DropDownList3.SelectedIndex >...

can someone one give me difference between web form and mobile web form and which or where or when i'm using the forms?
thanks Marc Hi Marc, Based on my understanding, you want to know the differences between the ASP.NET web application and ASP.NET mobile web application. If I have misunderstood you, please feel free to let me know. The ASP.NET forms are used to develop the ASP.NET pages for desktop browsers and The ASP.NET mobile forms are used to develop the ASP.NET pages for mobile device browsers. When we create the ASP.NET mobile web forms pages, we can use nearly all the features of ASP.NET. But there are a couple of compatibility issues: Error Handling and Reporting. Tracing. Using Redi...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

Selecting multiple value from Listbox control in web page
I have a search web page which has one textbox, listitem, search button and datagrid.1) How can i select multiple value in the listbox control. (Either by using Ctrl or shift key)2) After selecting multiple value from the listbox, how can i use those selected value to find the results in search query.Ex. My query is: select * from table where name = @Name@Name = All selected value from listbox control.Thanks Dim iCnt as Integer = myListBox.Items.Count For i = 0 To iCnt - 1 If myListBox.Items(i).Selected Then'Do something here End If NextHope it helpsZath Set the SelectionMode ...

Second SELECT-box doesn't show the selected value as SELECTED
Hi! I usually find what I look for in the other threads, but now I've spent two weeks searching and I still can't work this out, even though I'm sure the solution is easy:( Why doesn't my second dropdown-list show the selected value Arb (which shows in the url-window as for example myPage.asp?Ar=1976&Arb=1987) as selected? It manages to use the Ar-variable for the first SELECT-box, but the second box always has the first querystring-value selected, as if Arb="". I've also tried using a second sql-query, doing exactly as with the first SELECT-box, without success. Is ...

Getting values from a listbox (multiple -selection) and using it for searching database.
Dear All.I am new to although I have good knowledge of VB6I am developing a project which is a search page,I have one access database ,I want to connect a listbox with access table named 'state' having two digit code and it full name,i.e , NY--code --fullname -New York etc,How to populate the list box with fullname and 2 digit code as value...then i want user to select multiple option ,i.e, NewYork,virgina,etc and system must take it value for searching my database ..I am provide a code written in vb6 can any body edit this to be used in     &nbs...

Two Select statements in SP return no value in web form (only)
Hello. I  a SP with 2 select statements. If the first returns no results it does the second select. This works fine if I test it on the sql server. But when I try it in a webform using a sqldatasource it only returns a result if the first Select returns rows. If not It is an empty set (where I know it should not be. It returned resultrs on the SQL server). This is the code:1 ALTER PROCEDURE [SPName] 2 3 @SearchFor varchar(150) -- search string to compare with 4 5 AS 6 7 SELECT p.UserName, 8 9 (Select ImageName from ProfileImages Where ...

Return ListBox (Multiple) values from pop up child (javascript:ShowWindow) form listbox to parent form
Please advice me, how to get selected (multiple) values from a child pop up form constists of list box of available options back to parent window list box. I am not very familiar with this concept, please help me. If you have any URL or code samples send it to me. Thanks for your help. you would need to use javascript and send it by query string. I don't have the syntax right now as I am working on a similar problem myself. If I get it going soon I will post it....

how to select multiple files at a time using Ctrl+select and upload the attachments in C# .Net 1.0?
Hi, Do any one know how to select multiple files at a time using Ctrl+select and upload the attachments in C# .Net 1.0? I know that by placing 4 or 5 attachment controls we can do that.But I want to select multiple at a time. Do any one know this???  i think there is no option to select multiple file at a time ... instead you  can use Upload Multiple files each at one time like Gmail..  Regards,M.VenkatesanMy Blog : http://venkat-dotnetsamples.blogspot.comPlease remember to click “Mark as Answer” on the post that helps you,and to click “Unmark as Answer” if a marked po...

Assign multiple value in 'select'
I am trying to create sql to format table to display second colum values in one line per first column value. The before and after image should look like this; [ before ] id name 1 a 1 b 2 a 3 a 3 b 3 c 3 d [ after ] id nane 1 a b 2 a 3 a b c d The below query works on SQL server and Oracle but not on Sybase, it only return the last row. How do I make it work on Sybase ASE? I am using 15 create procedure testproc1 as declare @a int, @s varchar(100) select @a = 1 While @a<=(select count(distinct ...

selecting multiple values in a list box using code
Hi, I have a list box with certain values. The SelectionMode property of List box is set to Multiple. I want to select multiple items based on the values of the items in the Listbox using the code. Can any one please help.Thanks eg: for i = 0 to listbox.items.count - 1 if listbox.items(i).selected then Response.Write("Selected") else Response.Write("Selection Needed") end if next refer links:

Web resources about - Multiple-Select Listbox only returns first selected value (and I'm not using SelectedItem...) -

Gmail app updated with swipe to move between messages, multiple select edit mode
... right or left to move between messages without going back to the inbox. Version 2.1 also includes the ability to enable edit mode by selecting ...

How to select multiple languages for Google voice search
If you're bilingual, or visiting a foreign country, this can be really useful.

Select Multiple Messages in the New Gmail, Even With Sender Images Off
... of you that updated to Android's new Gmail app have probably noticed that your little checkboxes have disappeared. So how do you select multiple ...

iPad: Quick Select Multiple Photos
The iPad is great for editing and managing your photos on the go until you need to select multiple images, that is. Turns out there's an easy ...

You can now select multiple calls for deletion with Windows Phone 8.1 GDR1
... things like Cortana's Bluetooth integration or the new Store Live Tile. However, one area it did get right is the ability to select multiple ...

Select Walt Disney Parks Will Offer Discounts To U.S. Military Servicemen, But There Are Multiple Weird ...
... eligible active and retired U.S. Service Members or their spouses may purchase Disney 4-Day Military Promotional Tickets, there are multiple ...

Select and Delete Multiple Messages in Gmail
Does Gmail have a "select all" tool for messages you've labeled or filtered? It does and here's how to use it.

YouTube experiments with letting viewers choose multiple camera angles, to be tested by select performers ...
Frederic Lardinois / TechCrunch : YouTube experiments with letting viewers choose multiple camera angles, to be tested by select performers — ...

Google Drive for iOS update brings multiple file select, quick sharing, and more
... Drive for iOS brings a couple notable, highly-requested features to the app. Included in the update, users will now be able to select multiple ...

Select and Move Multiple Tabs to a New Window in Chrome
... (or that's what I tell myself to feel more comfortable about the chaos). If you ever need to move multiple tabs to a new window, select them ...

Resources last updated: 12/8/2015 5:30:04 AM