Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 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
 
Old December 15th, 2004, 12:44 PM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default LIST BOX HELP!!! PLEASE

I have a listbox (using VB.NET) with the following values:

Add
Delete
Edit
View

I want to "loop" through the list and ONLY write the SELECTED ITEMS to the screen. I have the below code writtern, but I only get the first selected item. EX: If I select Add & View, my reslut on the screen is Add Add.

----------START CODE---------------------
 Sub SaveUserPermission(ByVal s As Object, ByVal e As EventArgs)

        Dim mUserID, mPermissionID As Integer
        Dim txtPermission As String
        Dim LI As ListItem
        Dim objUserPermission As New clsUserPermission()

        mUserID = Session("editID")

        If lstbxPermissions.SelectedIndex = -1 Then
            Response.Write("NOTHING IS SELECTED!")
        End If

        For Each LI In lstbxPermissions.Items

           If LI.Selected = True Then

                txtPermission = lstbxPermissions.SelectedItem.Text

                Response.Write(txtPermission)
                Response.Write("<br>")
            End If

        Next

      End Sub
------------------END CODE-------------------------------

Please any help would be greatly appreciated!!!
Thanks,
MGR


 
Old April 29th, 2005, 10:29 AM
Authorized User
 
Join Date: Dec 2004
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
Send a message via Yahoo to whiterainbow
Default

Hi,

Instead of using "-1" for selected index, use "<0" (because the index will start from 0 so that you can display the selected item or in the 0th index put some static text so that you can check it with the if condition that the selectedindex>0.

your code should be like this:

'Populating List box

'looping code will go here
'Finally add this

lstbxPermissions.Items.Insert(0,"-Permissions-")

Now check whether the listbox's selectedindex>0

if lstbxPermissions.selectedindex<1 then

            Response.Write("NOTHING IS SELECTED!")
else
            For Each LI In lstbxPermissions.Items

           If LI.Selected = True Then

                txtPermission = lstbxPermissions.SelectedItem.Text

                Response.Write(txtPermission)
                Response.Write("<br>")
            End If

        Next
end if

SK





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





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