Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 1st, 2004, 04:57 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default selected items in asp:ListBox

Hi,

If I have an asp:ListBox control in my page that may have been populated but is now in a hidden panel, how can I show, in a summary section, all of the potentially selected items in an asp:Label control?

I.E., I want to do something like

Dim Item as ListItem

lblRptGrpSelected =
    For Each item In lstRptGrpSel.Items
        Response.Write(item.Text)
    Next

Thanks,

John
  #2 (permalink)  
Old July 1st, 2004, 05:32 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, figured it out:
I just need to know how I can make it NOT place a comma after the last item?
        Dim sb as New StringBuilder()

        Dim Item as ListItem

        For Each Item in lstRptGrpSel.Items
            sb.Append(Item.Text & ", ")
        Next

        lblRptGrpSum.Text = sb.ToString()
  #3 (permalink)  
Old July 2nd, 2004, 12:01 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Hi John,

You can change the logic slightly.

        Dim sb as New StringBuilder()

        Dim Item as ListItem

        Dim strList as String ' newly defined variable to store intermediate lists
        strList=""

        For Each Item in lstRptGrpSel.Items
            if(strList ="") then
                strList=Item.Text
            else
                strList=strList & "," & Item.Text
            end if

        Next

        sb.Append(strList)
        lblRptGrpSum.Text = sb.ToString()

Newly added code shown in bold.


Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList, DataSource and Selected Items kingroon ASP.NET 2.0 Basics 2 February 25th, 2008 10:41 AM
Number of selected items in a listbox sarah lee ASP.NET 2.0 Basics 2 May 17th, 2007 12:20 PM
Listview doesnt change after items are selected. hexOffender VB.NET 2002/2003 Basics 0 December 13th, 2006 12:28 PM
Cannot have multiple items selected in a DropDownL Ron Howerton ASP.NET 1.0 and 1.1 Basics 23 November 8th, 2006 04:29 PM
Cannot have multiple items selected in a DropDownL Ron Howerton ASP.NET 2.0 Basics 2 May 18th, 2006 04:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.