0

I have a dropdown list in my visual web part in c# and i am trying to bind dropdown list from sharepoint list items.

And I have the following code:

SPList list = web.Lists["Authors"];  
drpbind.DataSource = list.Items;  
drpbind.DataValueField = "Id";   
drpbind.DataTextField = "FullName";   
drpbind.DataBind(); 

And when I run this an error is being thrown saying that the Column FullName does not exist in the list. I tried to assign with column guid but its not working.

Help me please!

  • are you sure that the FullName has already existed in your list? this code should be working! – Mohamed El-Qassas MVP Mar 26 '17 at 11:30
  • Yes I am 100% sure that column FullName exist in my list – Nderon Hyseni Mar 26 '17 at 15:36
2

Make sure that you have provided the correct field name at drpbind.DataTextField = "FullName";

if it's not working Try to retrieve list items as data table as shown below

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
    {
        using (SPWeb web = site.OpenWeb())
        {
            SPList list = web.Lists["Authors"];
            drpbind.DataSource = list.Items.GetDataTable();
            drpbind.DataTextField = "FullName";
            drpbind.DataValueField = "ID";
            drpbind.DataBind();
        }
    }

Check a complete example at Bind a dropdown from SharePoint List via c#

  • 1
    list.Items.GetDataTable(); was the solution. Thanks Mohamed. – Zakir HC Jun 19 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.