Solved

C# not recognizing ListBox

Posted on 2011-02-18
5
692 Views
Last Modified: 2012-05-11
I have a ListBox in ASP.NET and when I attempt to call the SelectedItems.Count method, it throws me an error  


" 'System.Web.UI.WebControls.ListBox' does not contain a definition for 'SelectedItems' and no extension method 'SelectedItems' accepting a first argument of type 'System.Web.UI.WebControls.ListBox' could be found (are you missing a using directive or an assembly reference?)"
0
Comment
Question by:melli111
[X]
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
5 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34929210
There is no property 'SelectedItems' for ListBox
But 'SelectedItem' is there for ListBox
0
 
LVL 56

Expert Comment

by:HainKurt
ID: 34929236
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listbox_properties.aspx

SelectedIndex : Gets or sets the lowest ordinal index of the selected items in the list. (Inherited from ListControl.) SelectedItem  : Gets the selected item with the lowest index in the list control. (Inherited from ListControl.)
SelectedValue : Gets the value of the selected item in the list control, or selects the item in the list control that contains the specified value. (Inherited from ListControl.)
0
 
LVL 15

Author Comment

by:melli111
ID: 34929378
The ListBox that I am using contains several selected values.  How would I access this in C# code?
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 34929424
Try this code - You need to loop through the items and check whether it is selected or not
foreach (ListItem item in ListBox1.Items)
        {
            if (item.Selected)
            {
                // This item is selected - do your stuff here
            }
        }

Open in new window

0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 34933215
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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