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;
ddlCategory.DataBind();
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;}
}
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.