Binding a DropDownList to a Sharepoint List gives me an authentication prompt

I have a web part which is trying to bind a dropdownlist with the items in a Sharepoint 2007 list.

On this exact line ...

ddl.DataSource = list.Items;
it asks for authentication which seems quite odd.

Can anyone see if I'm doing something wrong?

String sharePointSite = "http://localhost/testsite/test1";
                String documentLibraryName = "Doc Lib 1";

                using (SPSite oSite = new SPSite(sharePointSite))
                    using (SPWeb oWeb = oSite.OpenWeb())

                        SPList list = oWeb.Lists[documentLibraryName];

                        ddl.DataSource = list.Items;
                        ddl.DataValueField = "Title"; // List field holding value 
                        ddl.DataTextField = "Title"; // List field holding name to be displayed on page 


Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi hmcgeehan,

Is it a document library or the list???

If its a document library you will need to use SPDocumentLibrary.

Or if it is a list itself
try iterating through the ListItemCollection and add each item to the dropdownlist.

foreach(listitem in listitemcollection)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shailaja KumarCommented:
I tried your code, it doesnt prompt for me, can you add the site to the trusted zones and then try again
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.