Populate listbox

Posted on 2009-02-10
Medium Priority
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.Attributes.Add(p.Code, p.Name);

Open in new window

Question by:Camillia
LVL 19

Accepted Solution

Albert Van Halen earned 2000 total points
ID: 23605955
Use this
lbSites.Items.Add(new ListItem(p.Code, p.Name)); // first parameter si text, second parameter is value

Open in new window


Author Comment

ID: 23606506
let me try.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

807 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