• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 827
  • Last Modified:

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

1 Solution
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)
Shailaja KumarCommented:
I tried your code, it doesnt prompt for me, can you add the site to the trusted zones and then try again
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now