We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Populate listbox

Camillia
Camillia asked
on
Medium Priority
2,120 Views
Last Modified: 2012-08-14
This cant be that hard but how can I populate a listbox. I'm using LINQ but it shouldnt matter.

If I use listbox.Items.Add(whatever)..this works but i need the "key" value also.

if I do lisbox.Attributes.Add(key,value).. i dont get anything in the list box. This is what i have.
var siteNames = from sValues in dc.LSite
                          where !sValues.Id.Equals(Guid.Empty)
                          select sValues;
 
        foreach (var p in siteNames)
        {
            //lbSites.Items.Add(p.Name);
            lbSites.Attributes.Add(p.Code, p.Name);
 
        }

Open in new window

Comment
Watch Question

Analyst developer
CERTIFIED EXPERT
Commented:
Use this
lbSites.Items.Add(new ListItem(p.Code, p.Name)); // first parameter si text, second parameter is value

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT

Author

Commented:
let me try.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.