views:

46

answers:

2

I have a Template via:

public class OwnedProvinces
{   public Guid ProvinceID;
    public string ProvinceName;
}

And I created a list with this template here:

List<OwnedProvinces> getinfo = (from upi in db.Utopia_Province_Data_Captured_Gens
                                            where upi.Owner_User_ID == SQLStatementsCS.UserID()
                                            where upi.Province_Name != string.Empty
                                            select new OwnedProvinces { ProvinceName = upi.Province_Name, ProvinceID = upi.Province_ID}).ToList();

The problem with this when I try to bind it to the Dropdown list like so:

  ddlSelectProvince.DataTextField =   "ProvinceName";
                ddlSelectProvince.DataValueField = "ProvinceID";
                ddlSelectProvince.DataSource = getinfo;
                ddlSelectProvince.DataBind();

It throws the Error:

DataBinding: 'OwnedProvinces' does not contain a property with the name 'ProvinceName'.

Basically, it can't find the property ProvinceName in the List, but makes no sense to me. If I do an anonymous query, it works, but when I assign it to the class OwnedPRovinces, it throws this error...

+2  A: 

Try to change the class like this

public class OwnedProvinces 
{   
    public Guid ProvinceID { get; set; } 
    public string ProvinceName { get; set; }
} 

The problem is that ProvinceID and ProvinceName are member variables not properties.

Branislav Abadjimarinov
+1  A: 

Problem is with your declaration -

public Guid ProvinceID;      
public string ProvinceName;      

are the fields, but not the properties. You should either change their definition or you should try to implement the IDataBindable interface, as written here: http://www.primaryobjects.com/CMS/Article95.aspx

    #region IDataBindable Members

    public List<NameValueType> ToList()
    {
        List<NameValueType> resultList = new List<NameValueType>();

        using (DataContext context = new DataContext())
        {
            List<Monster> itemList = context.Monsters.ToList();
            foreach (Monster item in itemList)
            {
                resultList.Add(new NameValueType(item.MonsterId.ToString(), item.Name));
            }
        }

        return resultList;
    }

    #endregion
VMAtm