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!

2
  • are you sure that the FullName has already existed in your list? this code should be working! Commented Mar 26, 2017 at 11:30
  • Yes I am 100% sure that column FullName exist in my list Commented Mar 26, 2017 at 15:36

1 Answer 1

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
  • 1
    list.Items.GetDataTable(); was the solution. Thanks Mohamed.
    – Zakir HC
    Commented Jun 19, 2019 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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