Click here to Skip to main content
11,920,394 members (41,413 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked

asp:DropDownList Binding to List

, 29 May 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
DropDownList requires the binding object to have a property

If you wonder why your <asp:DropDownList> is throwing a binding error when you try to get it to display a List<> of custom objects, it might be that your object has a variable, instead of a property.
So, this:

List<NameValue> listCategories = csNewsArticleProcess.GetNewsPublicCategories();
ddlCategory.DataValueField = "Value";
ddlCategory.DataTextField = "Name";
ddlCategory.DataSource = listCategories;

won't work if the NameValue is declared as:

public class NameValue
public string Name;
public string Value;

Instead it needs to be:

public class NameValue
public string Name { get; set;}
public string Value{ get; set;}


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Olga Tabulov
Software Developer The Code Project
Canada Canada
Olga has worked with a variety of large industrial applications before joining The Code Project and is now thrilled to apply all that knowledge at the best company on her resume!

She loves to make the site safer, more robust and even more user friendly every day and gets to spend most of her day doing the only thing she loves most - developing.

When not developing, she's either out with her husband and son or at the gym.

You may also be interested in...

Comments and Discussions

QuestionGood stuff Olga! Pin
Volynsky Alex30-May-14 12:12
professionalVolynsky Alex30-May-14 12:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151120.1 | Last Updated 29 May 2014
Article Copyright 2014 by Olga Tabulov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid